package com.augurit.gzcgwsp.smartformCsdlwj.service.impl;

import java.awt.Color;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import jxl.Sheet;
import jxl.Workbook;
import jxl.format.Alignment;
import jxl.format.VerticalAlignment;
import jxl.write.WritableCellFormat;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.jbpm.api.ProcessEngine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;

import com.augurit.common.system.util.WebContextUtils;
import com.augurit.common.system.web.auth.form.LoginUserForm;
import com.augurit.common.system.web.org.form.OmUserForm;
import com.augurit.common.util.HqlUtils;
import com.augurit.common.util.PageUtils;
import com.augurit.common.util.lang.StringUtils;
import com.augurit.gzcgwsp.commonex.system.service.org.IOmOrgServiceEX;
import com.augurit.gzcgwsp.commonex.util.lang.DateUtilsEX;
import com.augurit.gzcgwsp.csshlj.service.ICsshljCzService;
import com.augurit.gzcgwsp.csshlj.service.IShljYsService;
import com.augurit.gzcgwsp.excelimportexport.util.ExcelUtil;
import com.augurit.gzcgwsp.excelimportexport.util.FileUtil;
import com.augurit.gzcgwsp.excelimportexport.util.GetFileName;
import com.augurit.gzcgwsp.printDoc.entity.YwPrintDoc;
import com.augurit.gzcgwsp.printDoc.service.IYwPrintDocService;
import com.augurit.gzcgwsp.printDoc.web.form.YwPrintDocForm;
import com.augurit.gzcgwsp.sendNotice.service.IExchangeStateService;
import com.augurit.gzcgwsp.sendNotice.service.IYwMtbjlshInfoService;
import com.augurit.gzcgwsp.sendNotice.service.IYwWebserviceForWbService;
import com.augurit.gzcgwsp.sendNotice.service.IYwWebserviceInfoService;
import com.augurit.gzcgwsp.smartformCsdlwj.common.SmartDao;
import com.augurit.gzcgwsp.smartformCsdlwj.convert.YwHwShljqsConvertor;
import com.augurit.gzcgwsp.smartformCsdlwj.dao.SmartFormShljqsDao;
import com.augurit.gzcgwsp.smartformCsdlwj.dao.YwHwShljqsDao;
import com.augurit.gzcgwsp.smartformCsdlwj.entity.YwHwShljqs;
import com.augurit.gzcgwsp.smartformCsdlwj.entity.YwHwYsclgj;
import com.augurit.gzcgwsp.smartformCsdlwj.service.ISmartFormShljqsService;
import com.augurit.gzcgwsp.smartformCsdlwj.service.IYwHwCltfcsqkService;
import com.augurit.gzcgwsp.smartformCsdlwj.service.IYwHwLyqsclqksmService;
import com.augurit.gzcgwsp.smartformCsdlwj.service.IYwHwXminfoService;
import com.augurit.gzcgwsp.smartformCsdlwj.service.IYwHwYsclgjService;
import com.augurit.gzcgwsp.smartformCsdlwj.service.IYwHwYszzService;
import com.augurit.gzcgwsp.smartformCsdlwj.service.IYwHwZxqksmService;
import com.augurit.gzcgwsp.smartformCsdlwj.web.form.ShljqsForm;
import com.augurit.gzcgwsp.state.util.DocStyleUtils;
import com.augurit.gzcgwsp.state.util.ItextWordUtil;
import com.augurit.gzcgwsp.wfex.common.service.IWfServiceEX;
import com.augurit.gzcgwsp.ywcmn.entity.YwComSjtzsSccl;
import com.augurit.gzcgwsp.ywcmn.service.IYwComPrintService;
import com.augurit.gzcgwsp.ywcmn.service.IYwComQyxxService;
import com.augurit.gzcgwsp.ywcmn.service.IYwComSjclService;
import com.augurit.gzcgwsp.ywcmn.service.IYwComSjcllistService;
import com.augurit.gzcgwsp.ywcmn.service.IYwComSjtzsScclService;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComQyxxForm;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComSjclForm;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComSjcllistForm;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComSjtzsScclForm;
import com.augurit.smartform.service.IWfSupportService;
import com.augurit.wf.bi.convert.WfBusInstanceConvertor;
import com.augurit.wf.bi.service.IWfBusInstanceService;
import com.augurit.wf.bi.web.form.WfBusInstanceForm;
import com.augurit.wf.bi.web.form.WfBusInstanceTaskForm;
import com.augurit.wf.common.constant.WfConstant;
import com.augurit.wf.common.entity.WfBusInstance;
import com.augurit.wf.common.service.IWfService;
import com.augurit.wf.common.service.impl.WfBusClientServiceImpl;
import com.lowagie.text.Cell;
import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.BaseFont;

/**
 * <P>title:生活垃圾清扫serivce实现类</p>																								
 * <P>Description：</p>
 * <p>Copyright: Copyright (c) 2011 augurit</p>
 * <p>Company: 广州奥格智能科技</p>
 * History：
 * @author:zhangjun
 * @date Nov 15, 2011
 * @version 1.0
 */
@Service
@Transactional
public class SmartFormShljqsServiceImpl extends WfBusClientServiceImpl<ShljqsForm>  implements ISmartFormShljqsService{
	
	private static final Logger log=Logger.getLogger(SmartFormShljqsServiceImpl.class);
	
	@Autowired//道路挖掘dao
    private SmartFormShljqsDao smartFormShljqsDao;
	@Autowired
    private YwHwShljqsDao ywHwShljqsDao;
    @Autowired
    private IYwComPrintService ywComPrintService;    
    @Autowired
	private IYwComSjcllistService ywComSjcllistService;
	@Autowired
	private IYwComSjclService ywComSjclService;
	@Autowired
	private ICsshljCzService csshljCzService;
	@Autowired
    private IYwComQyxxService ywComQyxxService;
    @Autowired
	private IYwWebserviceInfoService ywWebserviceInfoService;
    @Autowired
    private IYwWebserviceForWbService ywWebserviceForWbService;
    @Autowired
    private IExchangeStateService exchangeStateService;	
	@Autowired
    private IWfService wfService;
	@Autowired
    private IWfServiceEX wfServiceEX;
	@Autowired
    private ProcessEngine processEngine;
	@Autowired
	private IOmOrgServiceEX omOrgServiceEX;	
	@Autowired
	private IShljYsService shljYsService;	
	@Autowired
	private IYwHwLyqsclqksmService ywHwLyqsclqksmService;
	@Autowired
	private IYwHwCltfcsqkService ywHwCltfcsqkService;
	@Autowired
	private IYwHwYszzService ywHwYszzService;
	@Autowired
	private IYwHwZxqksmService ywHwZxqksmService;	
	@Autowired
	private IYwHwYsclgjService ywHwYsclgjService;
	@Autowired
	private SmartDao smartDao;
	@Autowired
	private IWfSupportService wfSupportService;
	@Autowired
	private IWfBusInstanceService wfBusInstanceService;
	@Autowired
	private IYwHwXminfoService ywHwXminfoService;
	@Autowired
    private IYwMtbjlshInfoService ywMtbjlshInfoService;
	@Autowired
    private IYwComSjclService sjclService;
	@Autowired
	private IYwComSjtzsScclService ywComSjtzsScclService;
	@Autowired
	private IYwPrintDocService ywPrintDocService;
	
	
    //通过受理号获取案件
    public List<YwHwShljqs> getByAcceptNo(String acceptNo)
    {
    	String sql = "from YwHwShljqs t where t.acceptNo='" + acceptNo + "'";
    	List<YwHwShljqs> entityList= ywHwShljqsDao.find(sql);
        return entityList;
    }
    
    public Page<ShljqsForm> search(Page<ShljqsForm> page,
            List<PropertyFilter> filters) {
        // TODO Auto-generated method stub
        return null;
    }

    public Page<ShljqsForm> search(Page<ShljqsForm> page, ShljqsForm form) {
        // TODO Auto-generated method stub
		Page pg = PageUtils.newPageInstance(page);
		
		StringBuffer hql = new StringBuffer("from YwHwShljqs ps where 1=1");
		List values = new ArrayList();
		
		if(form != null){
		    if (StringUtils.isNotBlank(form.getSqdw())) {
		        hql.append(" and ps.qymc like '%" + form.getSqdw() + "%'");
		    }
		    hql.append(" and ps.fzh is not NULL ");
		}
		
		hql.append(HqlUtils.buildOrderBy(page, "ps"));
		smartDao.findPage(pg, hql.toString(), values);
		
		List<ShljqsForm> list = YwHwShljqsConvertor.convertVoListToFormList(pg.getResult());
		PageUtils.copy(pg, list, page);
        return page;
    }

    public void delete(Long... ids) {
        // TODO Auto-generated method stub
        
    }

    public ShljqsForm get(Long id) {
    	YwHwShljqs entity=null;
    	Session session=smartFormShljqsDao.getSession();
		Criteria criteria=session.createCriteria(YwHwShljqs.class);
		criteria.add(Restrictions.eq("id",id));
		List<YwHwShljqs> list=criteria.list();if(list!=null && list.size()>0){
		    entity=list.get(0);
		}
		ShljqsForm form = null;
		form = YwHwShljqsConvertor.convertVoToForm(entity);
		return form;
    }

    public void save(ShljqsForm... forms) {
    	if(forms != null)
			for(ShljqsForm form : forms)
				this.save(form);
    }

    public void save(ShljqsForm form) {
		System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"+form.getQymc());
		
        if (form == null) return;

        YwHwShljqs entity = new YwHwShljqs();
        //保存企业信息
        YwComQyxxForm qyxxForm = new YwComQyxxForm();
        if(StringUtils.isEmpty(form.getQybh())){
        	if(StringUtils.isNotBlank(form.getSqdw())){
            	YwComQyxxForm ywComQyxxForm = ywComQyxxService.getFormBySqdw(form.getSqdw(), "shljqssj");
            	if(ywComQyxxForm != null){
            		qyxxForm = ywComQyxxForm;
            	}
            }
        }
        YwHwShljqsConvertor.convertFormToQyxxForm(form, qyxxForm);
        qyxxForm.setTemplateCode("shljqssj");
        ywComQyxxService.update(qyxxForm);
        form.setQybh(qyxxForm.getId().toString());
        System.out.println("&&&&&&&&&&&&&&&&&&&&&  qyxxForm =  "+qyxxForm.getId());

        
        boolean isNewForm = false;
        if (StringUtils.isBlank(form.getAcceptNo())) {
        	//生成政务中心统一查询编号 开始
			Map<String,String> serialNoAndPasswordMap = null;
        	if("Y".equals(form.getSendNotice())){//网办，1
        		serialNoAndPasswordMap = ywMtbjlshInfoService.getSerialNoAndPassword("1");
        	}else{//大厅，0
        		serialNoAndPasswordMap = ywMtbjlshInfoService.getSerialNoAndPassword("0");
        	}
        	String serialNo = serialNoAndPasswordMap.get("serialNo");
        	String password = serialNoAndPasswordMap.get("password");
			form.setSerialNo(serialNo);
			form.setPassword(password);
			form.setAcceptNo(serialNo);
    		//生成政务中心统一查询编号 结束
            isNewForm = true;
        }
        YwHwShljqsConvertor.convertFormToVo(form, entity);
        System.out.println("&&&&&&&&&&&&&&&&&&&&&  后  "+entity.getSqdw());
        System.out.println("&&&&&&&&&&&&&&&&&&&&&  entity.getId() =  "+entity.getId());
        Session session = ywHwShljqsDao.getSessionFactory().openSession();
        session.save(entity);
        session.flush();
        session.close();
        form.setId(entity.getId());
        
        if (isNewForm) {
            sjclService.updateByNewForm(form.getId());
        }
	}
    
    public List getListById(Long id){
        String sql="select * from HW_SHLJQS_V1 where id="+id;
        return smartFormShljqsDao.getListById(sql);
    }

    /*
     * 查询受理日期(non-Javadoc)
     * @see com.augurit.gzcgwsp.smartformCsdlwj.service.ISmartFormCsdlwjService#getSlrq(java.lang.Long, java.lang.String, java.lang.Long)
     */
	public String getSlrq(Long id, String fileCode, Long tempId) {
		String date="";
        List<YwPrintDoc> docs=this.ywComPrintService.findDoc(id,fileCode,tempId);
        if(docs!=null && docs.size()>0){
	            YwPrintDoc doc=docs.get(0);
	            Date createDate=doc.getCreatDate();
	            try {
					date=DateUtilsEX.convertDate2Chinese(createDate);
				} catch (ParseException e) {
					e.printStackTrace();
				}
        }
		return date;
	}
	
	/**
	 * 修改方法
	 * @param form
	 * @param tablename
	 */
	public void doUpdate(ShljqsForm form,String tablename) {
		StringBuffer sb=new StringBuffer(" update "+tablename+" set ");
		sb.append(" fzjg='"+form.getFzjg()+"',");
		sb.append(" projectname='"+form.getProjectName()+"',");
		sb.append(" xkcontent='"+form.getXkContent()+"',");
		if(StringUtils.isNotBlank(form.getZsbh())){
			sb.append(" zsbh='"+form.getZsbh()+"',");
			sb.append(" fzh='"+form.getZsbh()+"',");//原来是zsbh证书编号现在修改为发证号
		}
		if(StringUtils.isNotBlank(form.getStartYear())){
			sb.append(" startYear='"+form.getStartYear()+"',");
		}
		if(StringUtils.isNotBlank(form.getStartMonth())){
			sb.append(" startMonth='"+form.getStartMonth()+"',");
		}
		if(StringUtils.isNotBlank(form.getStartDay())){
			sb.append(" startDay='"+form.getStartDay()+"',");
		}
		if(StringUtils.isNotBlank(form.getEndYear())){
			sb.append(" endYear='"+form.getEndYear()+"',");
		}
		if(StringUtils.isNotBlank(form.getEndMonth())){
			sb.append(" endMonth='"+form.getEndMonth()+"',");
		}
		if(StringUtils.isNotBlank(form.getEndDay())){
			sb.append(" endDay='"+form.getEndDay()+"',");
		}
		if(StringUtils.isNotBlank(form.getFzYear())){
			sb.append(" fzYear='"+form.getFzYear()+"',");
		}
		if(StringUtils.isNotBlank(form.getFzMonth())){
			sb.append(" fzMonth='"+form.getFzMonth()+"',");
		}
		if(StringUtils.isNotBlank(form.getFzDay())){
			sb.append(" fzDay='"+form.getFzDay()+"',");
		}
		if(StringUtils.isNotBlank(form.getJdTel())){
			sb.append(" jdTel='"+form.getJdTel()+"',");
		}
		
		
		
		//加了字段加入修改方法
		if(StringUtils.isNotBlank(form.getStartYear()) &&
			StringUtils.isNotBlank(form.getStartMonth()) && 
			StringUtils.isNotBlank(form.getStartDay())){
			sb.append(" jysjsstr='"+form.getStartYear()+"-"+form.getStartMonth()+
					"-"+form.getStartDay()+"',");//经营开始时间
		}
		if(StringUtils.isNotBlank(form.getEndYear()) &&
				StringUtils.isNotBlank(form.getEndMonth()) && 
				StringUtils.isNotBlank(form.getEndDay())){
				  sb.append(" jysjestr='"+form.getEndYear()+"-"+form.getEndMonth()+
						"-"+form.getEndDay()+"',");//经营结束时间
	    }
		if(StringUtils.isNotBlank(form.getFzYear()) &&
				StringUtils.isNotBlank(form.getFzMonth()) && 
				StringUtils.isNotBlank(form.getFzDay())){
				  sb.append(" fzsjstr='"+form.getFzYear()+"-"+form.getFzMonth()+
						"-"+form.getFzDay()+"',");//发证日期
		}
		sb.append(" xmmc='"+form.getProjectName()+"' ");//项目名称
		
		sb.append(" where id="+form.getId());
		int i=this.smartFormShljqsDao.updateDateBase(sb.toString());
	}

	public void doUpdateFb(ShljqsForm form, String tablename) {
		StringBuffer sb=new StringBuffer(" update "+tablename+" set ");
		sb.append(" fzjg='"+form.getFzjg()+"',");
		sb.append(" projectname='"+form.getProjectName()+"',");
		sb.append(" xkcontent='"+form.getXkContent()+"',");
		sb.append(" fzh='"+form.getZsbh()+"',");//原来是zsbh证书编号现在修改为发证号
//		sb.append(" startYear='"+form.getStartYear()+"',");
//		sb.append(" startMonth='"+form.getStartMonth()+"',");
//		sb.append(" startDay='"+form.getStartDay()+"',");
//		sb.append(" endYear='"+form.getEndDay()+"',");
//		sb.append(" endMonth='"+form.getEndMonth()+"',");
//		sb.append(" endDay='"+form.getEndDay()+"',");
//		sb.append(" fzYear='"+form.getFzYear()+"',");
//		sb.append(" fzMonth='"+form.getFzMonth()+"',");
//		sb.append(" fzDay='"+form.getFzDay()+"',");
		sb.append(" jdTel='"+form.getJdTel()+"',");
		//副本开始
		sb.append(" address='"+form.getAddress()+"',");
		sb.append(" fzrq='"+form.getFzrq()+"',");
		sb.append(" qywszb='"+form.getQywszb()+"',");
		sb.append(" qygrzb='"+form.getQygrzb()+"',");
		sb.append(" qygyzb='"+form.getQygyzb()+"',");
		sb.append(" qyhzzb='"+form.getQyhzzb()+"',");
		sb.append(" qylx='"+form.getQylx()+"',");
		sb.append(" qyManagerZc='"+form.getQyManagerZc()+"',");
		sb.append(" qyMaangerZw='"+form.getQyMaangerZw()+"',");
		sb.append(" qyManager='"+form.getQyManager()+"',");
		sb.append(" fddbrZw='"+form.getFddbrZw()+"',");
		sb.append(" frdb='"+form.getFddbr()+"',");
		sb.append(" fddbrZc='"+form.getFddbrZc()+"',");
		
		//加了字段加入修改方法
		if(StringUtils.isNotBlank(form.getStartYear()) &&
			StringUtils.isNotBlank(form.getStartMonth()) && 
			StringUtils.isNotBlank(form.getStartDay())){
			  sb.append(" jysjsstr='"+form.getStartYear()+"年"+form.getStartMonth()+
					"月"+form.getStartDay()+"日"+"',");//经营开始时间
		}
		if(StringUtils.isNotBlank(form.getEndYear()) &&
				StringUtils.isNotBlank(form.getEndMonth()) && 
				StringUtils.isNotBlank(form.getEndDay())){
				  sb.append(" jysjestr='"+form.getEndYear()+"年"+form.getEndMonth()+
						"月"+form.getEndDay()+"日"+"',");//经营结束时间
	    }
//		if(StringUtils.isNotBlank(form.getFzYear()) &&
//				StringUtils.isNotBlank(form.getFzMonth()) && 
//				StringUtils.isNotBlank(form.getFzDay())){
//				  sb.append(" fzsjstr='"+form.getFzYear()+"年"+form.getFzMonth()+
//						"月"+form.getFzDay()+"日"+"',");//发证日期
//		}
		if(StringUtils.isNotBlank(form.getStartYear())){
			sb.append(" startYear='"+form.getStartYear()+"', ");//年
		}
		if(StringUtils.isNotBlank(form.getStartMonth())){
			sb.append(" startMonth='"+form.getStartMonth()+"', ");//月
		}
		if(StringUtils.isNotBlank(form.getStartDay())){
			sb.append(" startDay='"+form.getStartDay()+"', ");//日
		}
		if(StringUtils.isNotBlank(form.getEndYear())){
			sb.append(" endYear='"+form.getEndYear()+"', ");//年
		}
		if(StringUtils.isNotBlank(form.getEndMonth())){
			sb.append(" endMonth='"+form.getEndMonth()+"', ");//月
		}
		if(StringUtils.isNotBlank(form.getEndDay())){
			sb.append(" endDay='"+form.getEndDay()+"', ");//日
		}
		if(StringUtils.isNotBlank(form.getXmnr1())){
			sb.append(" xmnr1='"+form.getXmnr1()+"', ");//项目名称
			sb.append(" startday1='"+form.getStartday1()+"', ");//项目记录
			sb.append(" endday1='"+form.getEndday1()+"', ");//项目记录
		}
		if(StringUtils.isNotBlank(form.getXmnr2())){
			sb.append(" xmnr2='"+form.getXmnr2()+"', ");//项目名称
			sb.append(" startday2='"+form.getStartday2()+"', ");//项目记录
			sb.append(" endday2='"+form.getEndday2()+"', ");//项目记录
		}
		if(StringUtils.isNotBlank(form.getXmnr3())){
			sb.append(" xmnr3='"+form.getXmnr3()+"', ");//项目名称
			sb.append(" startday3='"+form.getStartday3()+"', ");//项目记录
			sb.append(" endday3='"+form.getEndday3()+"',");//项目记录
		}
		
		if(StringUtils.isNotBlank(form.getXmnr4())){
			sb.append(" xmnr4='"+form.getXmnr4()+"', ");//项目名称
			sb.append(" startday4='"+form.getStartday4()+"', ");//项目记录
			sb.append(" endday4='"+form.getEndday4()+"',");//项目记录
		}
		if(StringUtils.isNotBlank(form.getXmnr5())){
			sb.append(" xmnr5='"+form.getXmnr5()+"', ");//项目名称
			sb.append(" startday5='"+form.getStartday5()+"', ");//项目记录
			sb.append(" endday5='"+form.getEndday5()+"', ");//项目记录
		}
		if(StringUtils.isNotBlank(form.getXmnr6())){
			sb.append(" xmnr6='"+form.getXmnr6()+"', ");//项目名称
			sb.append(" startday6='"+form.getStartday6()+"', ");//项目记录
			sb.append(" endday6='"+form.getEndday6()+"', ");//项目记录
		}
		
		sb.append(" gzsj1='"+form.getGzsj1()+"', ");//
		sb.append(" gzsj2='"+form.getGzsj2()+"', ");//
		sb.append(" gzsj3='"+form.getGzsj3()+"', ");//
		sb.append(" gzsj4='"+form.getGzsj4()+"', ");//
		sb.append(" gzsj5='"+form.getGzsj5()+"', ");//
		sb.append(" gzsj6='"+form.getGzsj6()+"', ");//
		sb.append(" zczb='"+form.getZczb()+"'");
		sb.append(" where id="+form.getId());
		int i=this.smartFormShljqsDao.updateDateBase(sb.toString());
		
	}
	
	//---获取待在办出证数据--
	public Page<ShljqsForm> getCzData(Page<ShljqsForm> page,ShljqsForm form){
		// 建立新的分页对象
		Page pg = PageUtils.newPageInstance(page);
		StringBuffer hql = new StringBuffer();
		hql.append(" select qs ");
		hql.append(" from Jbpm4HistTask task, Jbpm4HistProcinst proc, WfBusInstance inst,");
		hql.append(" YwHwShljqs qs ");
		hql.append(" where task.procInstId = proc.procInstId and proc.procInstId = inst.procInstId ");
		hql.append(" and inst.masterEntityKey=qs.id and inst.masterEntity='YwHwShljqs' ");
		hql.append(" and proc.state='active' ");
		hql.append(" and task.state='open'" );
		hql.append(" and task.activityName='gzryczh'");  //---办证环节
		
		Map<String, Object> values = new HashMap();
		if(form!=null){  //企业名称
			if(form.getQymc()!= null && form.getQymc().trim().length() > 0){
				hql.append(" and qs.qymc like :qymc");
				values.put("qymc", "%"+form.getQymc()+"%");
			}
		}
		
		smartFormShljqsDao.findPage(pg, hql.toString(),values);
		// 转换为Form对象列表并赋值到原分页对象中
		List<ShljqsForm> list = convertToList(pg.getResult());
		PageUtils.copy(pg, list, page);
		return page;
	}
	
	/*
	 * 主要用于证书打印(non-Javadoc)
	 * @see com.augurit.gzcgwsp.csshlj.service.ICsshljCzService#getForm(java.lang.String, java.lang.String)
	 */
	public ShljqsForm getForm(Long id, String tablename) {
		String sql=" select *　from "+tablename+" where id="+id;
		List list=smartFormShljqsDao.queryForList(sql);
		ShljqsForm form=new ShljqsForm();
		  if(list!=null && list.size()>0){
   		   Map<String,String> map=(Map<String,String>) list.get(0);
             form.setId(Long.valueOf((String)map.get("id")));
             form.setAcceptNo(map.get("accept_no"));
             form.setSqdw(map.get("qymc"));
             form.setYyzch(map.get("yyzzzch"));
             form.setYyzzzch(map.get("yyzzzch"));
             form.setZzjgdm(map.get("zzjgdm"));
             form.setCzdh(map.get("czdh"));
             form.setEmail(map.get("email"));
           //补交告知  //补交受理
             if(StringUtils.isNotBlank(map.get("bjgzsj"))){
            	 try {
					Date bjgzsjdate=DateUtilsEX.dateFormate(map.get("bjgzsj"), "yyyy年MM月dd日");
					 form.setBjgzsj(bjgzsjdate);
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
             }
             if(StringUtils.isNotBlank(map.get("bjslsj"))){
            	 try {
					Date bjslsjdate=DateUtilsEX.dateFormate(map.get("bjslsj"), "yyyy年MM月dd日");
					 form.setBjslsj(bjslsjdate);
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
             }
             
             form.setBjgzfcr(map.get("bjgzfcr"));
             form.setBjgzyy(map.get("bjgzyy"));
             form.setBjgzqd(map.get("bjgzqd"));
             form.setBjgzflag(map.get("bjgzflag"));
             
             form.setSldwcbrxm(map.get("sldwcbrxm"));
             form.setBjsljtdd(map.get("bjsljtdd"));
             form.setBjclqd(map.get("bjclqd"));
             //告知结束
             form.setYzbm(map.get("yzbm"));
             form.setWts(map.get("wts"));
             form.setQybh(map.get("qybh"));
             form.setZsbh(map.get("fzh"));
             form.setFddbr(map.get("frdb"));
             form.setLxdh(map.get("lxrdh"));
             form.setLxdh2(map.get("lxdh2"));
             form.setCzdh2(map.get("czdh2"));
             form.setEmail2(map.get("email2"));
             form.setBz(map.get("bz"));
//             form.setProjectName(map.get("projectname"));
//             form.setXkContent((map.get("xkcontent")));

             form.setFwnrqs(map.get("fwnrqs"));
             form.setFwnrsj(map.get("fwnrsj"));
             form.setFwnrys(map.get("fwnrys"));
             form.setProjectName(map.get("xmmc"));//项目名称
             form.setXkContent((map.get("xkcontent")));
             form.setLxdh(map.get("lxdh"));
             String startDate=map.get("jysjsstr");//经营开始时间
             String endDate=map.get("jysjestr");//经营结束时间
             String fzsj=map.get("fzsjstr");//发证时间
             form.setXmnr1(map.get("xmnr1"));//副证的项目登记
             form.setXmnr2(map.get("xmnr2")==null?"":map.get("xmnr2"));//副证的项目登记
             form.setXmnr3(map.get("xmnr3"));//副证的项目登记
             form.setXmnr4(map.get("xmnr4"));//副证的项目登记
             form.setXmnr5(map.get("xmnr5"));//副证的项目登记
             form.setXmnr6(map.get("xmnr6"));//副证的项目登记
             form.setStartday4(map.get("startday4"));//副证的项目登记
             form.setStartday5(map.get("startday5"));//副证的项目登记
             form.setStartday6(map.get("startday6"));//副证的项目登记
             form.setStartday1(map.get("startday1"));
             form.setStartday2(map.get("startday2"));
             form.setStartday3(map.get("startday3"));
             form.setEndday4(map.get("endday4"));
             form.setEndday5(map.get("endday5"));
             form.setEndday6(map.get("endday6"));
             form.setEndday1(map.get("endday1"));
             form.setEndday2(map.get("endday2"));
             form.setEndday3(map.get("endday3"));
             form.setGzsj1(map.get("gzsj1"));
             form.setGzsj2(map.get("gzsj2"));
             form.setGzsj3(map.get("gzsj3"));
             form.setGzsj4(map.get("gzsj4"));
             form.setGzsj5(map.get("gzsj5"));
             form.setGzsj5(map.get("gzsj6"));
             if(StringUtils.isBlank(map.get("xkcontent"))){
            	 form.setXkContent("广州市（陆域）城市生活垃圾经营性清扫、收集、运输服务");
             }
             if(StringUtils.isNotBlank(startDate) && startDate.length()>=10){
     			form.setStartYear(startDate.substring(0,4));
     			form.setStartMonth(startDate.substring(5,7));
     			form.setStartDay(startDate.substring(8,10));
     		 }else if(StringUtils.isNotBlank(map.get("startyear")) && StringUtils.isNotBlank(map.get("startmonth")) && StringUtils.isNotBlank(map.get("startday"))){
     			form.setStartYear(map.get("startyear"));
     			form.setStartMonth(map.get("startmonth"));
     			form.setStartDay(map.get("startday"));
     		 }else{
     			form.setStartYear(DateUtilsEX.getCurYear());
     			form.setStartMonth(DateUtilsEX.getCurMonth());
     			form.setStartDay(DateUtilsEX.getCurDay());
     		 }
             if(StringUtils.isNotBlank(endDate) && endDate.length()>=10){
            	form.setEndYear(endDate.substring(0,4));
            	form.setEndMonth(endDate.substring(5,7));
            	form.setEndDay(endDate.substring(8,10));
      		 }else if(StringUtils.isNotBlank(map.get("endyear")) && StringUtils.isNotBlank(map.get("endmonth")) && StringUtils.isNotBlank(map.get("endday"))){
     			form.setEndYear(map.get("endyear"));
     			form.setEndMonth(map.get("endmonth"));
     			form.setEndDay(map.get("endday"));
     		 }else{
      			form.setEndYear(DateUtilsEX.getCurYear());
      			form.setEndMonth(DateUtilsEX.getCurMonth());
      			form.setEndDay(DateUtilsEX.getCurDay());
      		}
            if(StringUtils.isNotBlank(fzsj) && fzsj.length()>=10){
       			form.setFzYear(fzsj.substring(0,4));
       			form.setFzMonth(fzsj.substring(5,7));
       			form.setFzDay(fzsj.substring(8,10));
       		}else if(StringUtils.isNotBlank(map.get("fzyear")) && StringUtils.isNotBlank(map.get("fzmonth")) && StringUtils.isNotBlank(map.get("fzday"))){
       			form.setFzYear(map.get("fzyear"));
     			form.setFzMonth(map.get("fzmonth"));
     			form.setFzDay(map.get("fzday"));
     		 }else{
    			form.setFzYear(DateUtilsEX.getCurYear());
      			form.setFzMonth(DateUtilsEX.getCurMonth());
      			form.setFzDay(DateUtilsEX.getCurDay());
       		}
             //form.setStartYear(map.get("startyear"));
             //form.setStartMonth(map.get("startmonth"));
             //form.setStartDay(map.get("startday"));
             //form.setEndDay(map.get("endday"));
             //form.setEndMonth(map.get("endmonth"));
             //form.setEndYear(map.get("endyear"));
             //form.setFzDay(map.get("fzday"));
             //form.setFzYear(map.get("fzyear"));
             //form.setFzMonth(map.get("fzmonth"));
             form.setJdTel(map.get("jdtel"));
             form.setAddress(map.get("address"));
             form.setQyMaangerZw(map.get("qymaangerzw"));
             form.setQyManager(map.get("qymanager"));
             form.setQyManagerZc(map.get("qymanagerzc"));
             form.setQylx(map.get("qylx"));
             form.setQygyzb(map.get("qygyzb"));
             form.setQygrzb(map.get("qygrzb"));
             form.setQyhzzb(map.get("qyhzzb"));
             form.setQywszb(map.get("qywszb"));
             form.setFddbrZc(map.get("fddbrzc"));
             form.setFddbrZw(map.get("fddbrzw"));
             form.setAddress(map.get("address"));
             form.setZczb(map.get("zczb"));
             form.setFzrq(map.get("fzrq"));
             form.setFzjg(map.get("fzjg")==null?"广州市城市管理委员会":map.get("fzjg"));
             
             form.setCbyw(map.get("cbyw"));
             form.setSjr(map.get("sjr"));
             form.setFzh(map.get("fzh"));
             form.setFzsjstr(map.get("fzsjstr"));
             form.setValidstarttime(startDate);
             form.setValidendtime(endDate);
             form.setFzsjstr(map.get("fzsjstr"));
 			//设置收件通知书书签
             form.setCbyw2(form.getCbyw());
             form.setCbyw3(form.getCbyw());
             form.setCbyw4(form.getCbyw());
             form.setFrdb2(form.getFddbr());
             form.setAcceptNo2(map.get("accept_no"));
//             String tbrqStr = simpleDateFormat.format(form.getTbrq());
             if(StringUtils.isNotBlank(map.get("tbrq"))){
            	 form.setTbrq(DateUtilsEX.getStringToDate(map.get("tbrq")));
             }
            
             form.setTbrq2(map.get("tbrq"));
             form.setTbrq3(map.get("tbrq"));
             form.setCurDate2(map.get("tbrq"));
             form.setCurDate3(map.get("tbrq"));
             form.setSjr2(form.getSjr());
             form.setSajg("广州市城市管理委员会");
             form.setSajg2(form.getSajg());
             form.setQymc2(form.getSqdw());
             form.setQymc(form.getSqdw());
             form.setFrdb(form.getFddbr());
             
             if(StringUtils.isBlank(form.getAddress())){
            	 form.setAddress(map.get("bgzs"));
            	 
             }
             if(form.getFzrq()==null){
            	  String fzrq=form.getFzYear()+"-"+form.getFzMonth()+"-"+form.getFzDay();
            	  form.setFzrq(fzrq);
             }
           
             List list2 =new ArrayList();
             list2 = ywHwXminfoService.getFbXminfo(id, "shljqssj");
             if(list2!=null && list2.size()>0){
                 Map<String, String> map2 =(Map<String, String>) list2.get(0);
                 form.setXmid1(Long.parseLong(map2.get("xmid")));
                 form.setXmnr1(map2.get("xmnr"));
                 form.setStartday1(map2.get("startday"));
                 form.setEndday1(map2.get("endday"));
                 form.setGzsj1(map2.get("gzsj"));
                 if(list2.size()>1){
                	 map2 =(Map<String, String>) list2.get(1);
                     form.setXmid2(Long.parseLong(map2.get("xmid")));
                     form.setXmnr2(map2.get("xmnr"));
                     form.setStartday2(map2.get("startday"));
                     form.setEndday2(map2.get("endday"));
                     form.setGzsj2(map2.get("gzsj"));
                 }
                 if(list2.size()>2){
                	 map2 =(Map<String, String>) list2.get(2);
                     form.setXmid3(Long.parseLong(map2.get("xmid")));
                     form.setXmnr3(map2.get("xmnr"));
                     form.setStartday3(map2.get("startday"));
                     form.setEndday3(map2.get("endday"));
                     form.setGzsj3(map2.get("gzsj"));
                 }
                 if(list2.size()>3){
                	 map2 =(Map<String, String>) list2.get(3);
                     form.setXmid4(Long.parseLong(map2.get("xmid")));
                     form.setXmnr4(map2.get("xmnr"));
                     form.setStartday4(map2.get("startday"));
                     form.setEndday4(map2.get("endday"));
                     form.setGzsj4(map2.get("gzsj"));
                 }
                 if(list2.size()>4){
                	 map2 =(Map<String, String>) list2.get(4);
                     form.setXmid5(Long.parseLong(map2.get("xmid")));
                     form.setXmnr5(map2.get("xmnr"));
                     form.setStartday5(map2.get("startday"));
                     form.setEndday5(map2.get("endday"));
                     form.setGzsj5(map2.get("gzsj"));
                 }
                 if(list2.size()>5){
                	 map2 =(Map<String, String>) list2.get(5);
                     form.setXmid6(Long.parseLong(map2.get("xmid")));
                     form.setXmnr6(map2.get("xmnr"));
                     form.setStartday6(map2.get("startday"));
                     form.setEndday6(map2.get("endday"));
                     form.setGzsj6(map2.get("gzsj"));
                 }
             }
          }
		return form;
	}
	
	/**
	 * 获取收件通知书里面的材料列表
	 * @param form
	 * @return
	 */
	public ShljqsForm getSjtzsField(ShljqsForm form){
		form.setSerialNo2(form.getSerialNo());
		form.setPassword2(form.getPassword());
		Long id = form.getId();
		YwComSjcllistForm sjclListForm=new YwComSjcllistForm();
		sjclListForm.setAjid(id);
		sjclListForm.setTplcode("shljqssj");
        List<YwComSjcllistForm> sjclList = ywComSjcllistService.getList(sjclListForm);
        YwComSjclForm fkForm = new YwComSjclForm();
//        fkForm.setFkid(form.getQyid());
        fkForm.setAjid(id);
        fkForm.setTplcode("shljqssj");
        List<YwComSjclForm> sjclTpl = ywComSjclService.getList(fkForm);
        
        //查询是否有已经选择的,有的话，默认选中
		YwComSjtzsScclForm ywComSjtzsScclForm = new YwComSjtzsScclForm();
		ywComSjtzsScclForm.setAcceptNo(form.getAcceptNo());
		ywComSjtzsScclForm.setAjid(form.getId());
		ywComSjtzsScclForm.setTplcode("shljqssj");
		List<YwComSjtzsScclForm> checkedsjclList = ywComSjtzsScclService.getList(ywComSjtzsScclForm);
		
		//
        for (YwComSjcllistForm listForm : sjclList) {
            boolean hasExists = false;
            for (YwComSjclForm tplForm : sjclTpl) {
                if (tplForm.getTplid() != null && listForm.getId().longValue() == tplForm.getTplid().longValue()) {
                    if (StringUtils.isNotBlank(tplForm.getFilepath())) {
                        listForm.setState("1");
                        listForm.setHasfile("1");
                        listForm.setFilename(tplForm.getFilename());
                        listForm.setFilepath(tplForm.getFilepath());
                        listForm.setFiletype(tplForm.getFiletype());
                    } else {
                        listForm.setState("0");
                        listForm.setHasfile("0");
                    }
                    if (tplForm.getYjs() != null) {
                        listForm.setYjs(Long.valueOf(tplForm.getYjs()));
                    }
                    if (tplForm.getFyjs() != null) {
                        listForm.setFyjs(Long.valueOf(tplForm.getFyjs()));
                    }
                    listForm.setClid(tplForm.getId());
                    if ("1".equals(listForm.getSfdz())) {
                        listForm.setDisabled("1");
                    } else {
                    	listForm.setDisabled("0");
	                    if (tplForm.getSfdz() == null) {
	                    	listForm.setSfdz("0");
	                    } else {
	                    	listForm.setSfdz(tplForm.getSfdz());
	                    }
                    }
                    hasExists = true;
                }
            }
            if (!hasExists) {
                listForm.setState("0");
                listForm.setHasfile("0");
                if ("1".equals(listForm.getSfdz())) {
                    listForm.setDisabled("1");
                } else {
                    listForm.setDisabled("0");
                }
            }
            if(checkedsjclList != null && checkedsjclList.size()>0){
            	for(YwComSjtzsScclForm ywComSjtzsScclForm2 : checkedsjclList){
            		System.out.println("ywComSjtzsScclForm2.getClid() = "+ywComSjtzsScclForm2.getClid()+"---------listForm.getId() ="+listForm.getId());
            		long a = ywComSjtzsScclForm2.getClid();
            		long b = listForm.getId();
            		if(a == b){            			
            			listForm.setSfdz("1");
            			System.out.println("1111111 = "+listForm.getSfdz());
            		}
            	}
            }
        }
        if(sjclList.size()>0)
		{
				YwComSjcllistForm sjclForm01=sjclList.get(0);
				form.setTitleRow101(sjclForm01.getTitle());
				form.setTitleRow102(sjclForm01.getTitle());
				form.setFyjsRow101(sjclForm01.getFyjs());
				form.setFyjsRow102(sjclForm01.getFyjs());
				form.setFsRow101(sjclForm01.getYjs()+sjclForm01.getFyjs());
				form.setFsRow102(sjclForm01.getYjs()+sjclForm01.getFyjs());
				if("1".equals(sjclForm01.getSfdz()))
				{
					form.setSfdzRow101("√");
					form.setSfdzRow102("√");
				}else{
					form.setSfdzRow101("");
					form.setSfdzRow102("");
				}
				
				YwComSjcllistForm sjclForm02=sjclList.get(1);
				form.setTitleRow201(sjclForm02.getTitle());
				form.setTitleRow202(sjclForm02.getTitle());
				form.setFyjsRow201(sjclForm02.getFyjs());
				form.setFyjsRow202(sjclForm02.getFyjs());
				form.setFsRow201(sjclForm02.getYjs()+sjclForm02.getFyjs());
				form.setFsRow202(sjclForm02.getYjs()+sjclForm02.getFyjs());
				if("1".equals(sjclForm02.getSfdz()))
				{
					form.setSfdzRow201("√");
					form.setSfdzRow202("√");
				}else{
					form.setSfdzRow201("");
					form.setSfdzRow202("");
				}
				
				
				YwComSjcllistForm sjclForm03=sjclList.get(2);
				form.setTitleRow301(sjclForm03.getTitle());
				form.setTitleRow302(sjclForm03.getTitle());
				form.setFyjsRow301(sjclForm03.getFyjs());
				form.setFyjsRow302(sjclForm03.getFyjs());
				form.setFsRow301(sjclForm03.getYjs()+sjclForm03.getFyjs());
				form.setFsRow302(sjclForm03.getYjs()+sjclForm03.getFyjs());
				if("1".equals(sjclForm03.getSfdz()))
				{
					form.setSfdzRow301("√");
					form.setSfdzRow302("√");
				}else{
					form.setSfdzRow301("");
					form.setSfdzRow302("");
				}
				
				YwComSjcllistForm sjclForm04=sjclList.get(3);
				form.setTitleRow401(sjclForm04.getTitle());
				form.setTitleRow402(sjclForm04.getTitle());
				form.setFyjsRow401(sjclForm04.getFyjs());
				form.setFyjsRow402(sjclForm04.getFyjs());
				form.setFsRow401(sjclForm04.getYjs()+sjclForm04.getFyjs());
				form.setFsRow402(sjclForm04.getYjs()+sjclForm04.getFyjs());
				if("1".equals(sjclForm04.getSfdz()))
				{
					form.setSfdzRow401("√");
					form.setSfdzRow402("√");
				}else{
					form.setSfdzRow401("");
					form.setSfdzRow402("");
				}
				
				
				YwComSjcllistForm sjclForm05=sjclList.get(4);
				form.setTitleRow501(sjclForm05.getTitle());
				form.setTitleRow502(sjclForm05.getTitle());
				form.setFyjsRow501(sjclForm05.getFyjs());
				form.setFyjsRow502(sjclForm05.getFyjs());
				form.setFsRow501(sjclForm05.getYjs()+sjclForm05.getFyjs());
				form.setFsRow502(sjclForm05.getYjs()+sjclForm05.getFyjs());
				
				if("1".equals(sjclForm05.getSfdz()))
				{
					form.setSfdzRow501("√");
					form.setSfdzRow502("√");
				}else{
					form.setSfdzRow501("");
					form.setSfdzRow502("");
				}
				
				YwComSjcllistForm sjclForm06=sjclList.get(5);
				form.setTitleRow601(sjclForm06.getTitle());
				form.setTitleRow602(sjclForm06.getTitle());
				form.setFyjsRow601(sjclForm06.getFyjs());
				form.setFyjsRow602(sjclForm06.getFyjs());
				form.setFsRow601(sjclForm06.getYjs()+sjclForm06.getFyjs());
				form.setFsRow602(sjclForm06.getYjs()+sjclForm06.getFyjs());
				
				if("1".equals(sjclForm06.getSfdz()))
				{
					form.setSfdzRow601("√");
					form.setSfdzRow602("√");
				}else{
					form.setSfdzRow601("");
					form.setSfdzRow602("");
				}
				
				YwComSjcllistForm sjclForm07=sjclList.get(6);
				form.setTitleRow701(sjclForm07.getTitle());
				form.setTitleRow702(sjclForm07.getTitle());
				form.setFyjsRow701(sjclForm07.getFyjs());
				form.setFyjsRow702(sjclForm07.getFyjs());
				form.setFsRow701(sjclForm07.getYjs()+sjclForm07.getFyjs());
				form.setFsRow702(sjclForm07.getYjs()+sjclForm07.getFyjs());
				
				if("1".equals(sjclForm07.getSfdz()))
				{
					form.setSfdzRow701("√");
					form.setSfdzRow702("√");
				}else{
					form.setSfdzRow701("");
					form.setSfdzRow702("");
				}
				
				YwComSjcllistForm sjclForm08=sjclList.get(7);
				form.setTitleRow801(sjclForm08.getTitle());
				form.setTitleRow802(sjclForm08.getTitle());
				form.setFyjsRow801(sjclForm08.getFyjs());
				form.setFyjsRow802(sjclForm08.getFyjs());
				form.setFsRow801(sjclForm08.getYjs()+sjclForm08.getFyjs());
				form.setFsRow802(sjclForm08.getYjs()+sjclForm08.getFyjs());
				
				if("1".equals(sjclForm08.getSfdz()))
				{
					form.setSfdzRow801("√");
					form.setSfdzRow802("√");
				}else{
					form.setSfdzRow801("");
					form.setSfdzRow802("");
				}
				
				YwComSjcllistForm sjclForm09=sjclList.get(8);
				form.setTitleRow901(sjclForm09.getTitle());
				form.setTitleRow902(sjclForm09.getTitle());
				form.setFyjsRow901(sjclForm09.getFyjs());
				form.setFyjsRow902(sjclForm09.getFyjs());
				form.setFsRow901(sjclForm09.getYjs()+sjclForm09.getFyjs());
				form.setFsRow902(sjclForm09.getYjs()+sjclForm09.getFyjs());
				
				if("1".equals(sjclForm09.getSfdz()))
				{
					form.setSfdzRow901("√");
					form.setSfdzRow902("√");
				}else{
					form.setSfdzRow901("");
					form.setSfdzRow902("");
				}
				
				YwComSjcllistForm sjclForm10=sjclList.get(9);
				form.setTitleRow1001(sjclForm10.getTitle());
				form.setTitleRow1002(sjclForm10.getTitle());
				form.setFyjsRow1001(sjclForm10.getFyjs());
				form.setFyjsRow1002(sjclForm10.getFyjs());
				form.setFsRow1001(sjclForm10.getYjs()+sjclForm10.getFyjs());
				form.setFsRow1002(sjclForm10.getYjs()+sjclForm10.getFyjs());
				
				if("1".equals(sjclForm10.getSfdz()))
				{
					form.setSfdzRow1001("√");
					form.setSfdzRow1002("√");
				}else{
					form.setSfdzRow1001("");
					form.setSfdzRow1002("");
				}
				
				YwComSjcllistForm sjclForm11=sjclList.get(10);
				form.setTitleRow1101(sjclForm11.getTitle());
				form.setTitleRow1102(sjclForm11.getTitle());
				form.setFyjsRow1101(sjclForm11.getFyjs());
				form.setFyjsRow1102(sjclForm11.getFyjs());
				form.setFsRow1101(sjclForm11.getYjs()+sjclForm11.getFyjs());
				form.setFsRow1102(sjclForm11.getYjs()+sjclForm11.getFyjs());
				
				if("1".equals(sjclForm11.getSfdz()))
				{
					form.setSfdzRow1101("√");
					form.setSfdzRow1102("√");
				}else{
					form.setSfdzRow1101("");
					form.setSfdzRow1102("");
				}
		}
        
        
		return form;
	}

	/*
	 * (non-Javadoc)
	 * @see com.augurit.gzcgwsp.smartformCsdlwj.service.ISmartFormShljqsService#writeFbData(com.augurit.gzcgwsp.smartformCsdlwj.web.form.ShljqsForm, java.lang.String, java.lang.String)
	 */
	public String writeFbData(ShljqsForm form, String context, String inpath) {
		inpath=inpath.replace("/", File.separator);
        String tempOutPath="Templates/csshlj/outfile/xkzfb/outfile";
        String fileName = GetFileName.getFileName("xls");
        tempOutPath=this.buildPath(tempOutPath,fileName);
        String outfilepath=context+"/"+tempOutPath;
        outfilepath=outfilepath.replace("/", File.separator);
        String outdir=outfilepath.substring(0,outfilepath.lastIndexOf(File.separator));
        File file=new File(outdir);
        if(!file.exists()){
            file.mkdirs();
        }
        writerFbDataExcel(inpath,outfilepath,form);
        
		return tempOutPath;
	}

	/*
	 * (non-Javadoc)
	 * @see com.augurit.gzcgwsp.smartformCsdlwj.service.ISmartFormShljqsService#writeXkzData(com.augurit.gzcgwsp.smartformCsdlwj.web.form.ShljqsForm, java.lang.String, java.lang.String)
	 */
	public String writeXkzData(ShljqsForm form, String context, String inpath) {
		inpath=inpath.replace("/", File.separator);
        String tempOutPath="Templates/csshlj/outfile";
        String fileName = GetFileName.getFileName("xls");
        tempOutPath=this.buildPath(tempOutPath,fileName);
        String outfilepath=context+"/"+tempOutPath;
        outfilepath=outfilepath.replace("/", File.separator);
        String outdir=outfilepath.substring(0,outfilepath.lastIndexOf(File.separator));
        File file=new File(outdir);
        if(!file.exists()){
            file.mkdirs();
        }
        writerDataExcel(inpath,outfilepath,form); 
        try {//删除其他文件
			FileUtil.delDir(outdir,fileName);
		} catch (IOException e) {
			log.error("删除文件错误"+e);
		}
		return tempOutPath;
	}

    /**
     * 复制模版写入数据
     * @param inpath
     * @param outfilepath
     * @param form
     */
    private void writerDataExcel(String inpath, String outfilepath,
    		ShljqsForm form) {
        WritableWorkbook wwb;
        try {
            wwb = ExcelUtil.createWorkbookByOld(inpath, outfilepath);
            WritableSheet wsOne = ExcelUtil.getWritableSheetByIndex(wwb, 0);
            copyZsData(wsOne,form);
            wwb.write();
            wwb.close();
        } catch (Exception e) {
            log.error("写文件错误"+e);
        } 
    }
    
    /**
     * 复制副本写入数据
     * @param inpath
     * @param outfilepath
     * @param form
     */
    private void writerFbDataExcel(String inpath, String outfilepath,
    		ShljqsForm form) {
        WritableWorkbook wwb;
        try {
            wwb = ExcelUtil.createWorkbookByOld(inpath, outfilepath);
            WritableSheet wsOne = ExcelUtil.getWritableSheetByIndex(wwb, 0);
            WritableSheet wsTwo = ExcelUtil.getWritableSheetByIndex(wwb, 1);
            copyFbData(wsOne,form);
            copyFbData2(wsTwo,form);
            wwb.write();
            wwb.close();
        } catch (Exception e) {
            log.error("写文件错误"+e);
        } 
    }

    /**
     * 写数据
     * @param wsOne
     * @param form
     */
    private void copyFbData(WritableSheet wsOne, ShljqsForm form) {
    	 try {
    		 WritableCellFormat wcf=ExcelUtil.createCellFormat("宋体", 14, Alignment.LEFT, VerticalAlignment.CENTRE,false);
			 WritableCellFormat wcf1=ExcelUtil.createCellFormat("宋体", 14, Alignment.LEFT, VerticalAlignment.CENTRE,true);
			 WritableCellFormat wcf2=ExcelUtil.createCellFormat("宋体", 12, Alignment.CENTRE, VerticalAlignment.CENTRE,false);
			 WritableCellFormat wcf3=ExcelUtil.createCellFormat("宋体", 14, Alignment.LEFT, VerticalAlignment.TOP,false);
			 WritableCellFormat wcfdate=ExcelUtil.createCellFormat("宋体", 8, Alignment.CENTRE, VerticalAlignment.CENTRE,false);
			 WritableCellFormat wcfxmnr=ExcelUtil.createCellFormat("宋体", 10, Alignment.LEFT, VerticalAlignment.TOP,true);
			 WritableCellFormat wcfxmrq=ExcelUtil.createCellFormat("宋体", 10, Alignment.CENTRE, VerticalAlignment.CENTRE,false);
			 wcf.setLocked(false);
			 wcf1.setLocked(false);
			 wcf2.setLocked(false);
			 wcf3.setLocked(false);
			 wcfdate.setLocked(false);
			 ExcelUtil.modiStrCell2(wsOne, 1, 1, form.getSqdw()==null?"":form.getSqdw(), wcf);//申请单位
			 ExcelUtil.modiStrCell2(wsOne,1, 2, form.getAddress()==null?"":form.getAddress(), wcf1);//地址
			 ExcelUtil.modiStrCell2(wsOne,1, 3, form.getYyzch()==null?"":form.getYyzch(), wcf);//营业执照注册号
			 ExcelUtil.modiStrCell2(wsOne,1, 4, form.getZczb()==null?"":form.getZczb(), wcf);//注册资本
			 ExcelUtil.modiStrCell2(wsOne,1, 6, form.getFddbr()==null?"":form.getFddbr(), wcf2);//法定代表人
			 ExcelUtil.modiStrCell2(wsOne,8, 6, form.getFddbrZw()==null?"":form.getFddbrZw(), wcf2);//职务
			 ExcelUtil.modiStrCell2(wsOne,17, 6, form.getFddbrZc()==null?"":form.getFddbrZc(), wcf2);//职称
			 ExcelUtil.modiStrCell2(wsOne,1, 8, form.getQyManager()==null?"":form.getQyManager(), wcf2);//企业负责人
			 ExcelUtil.modiStrCell2(wsOne,8, 8,form.getQyMaangerZw()==null?"":form.getQyMaangerZw(), wcf2);//职务
			 ExcelUtil.modiStrCell2(wsOne,17, 8,form.getQyManagerZc()==null?"":form.getQyManagerZc(), wcf2);//职称
			 if("1".equals(form.getQylx())){//内资企业
				  ExcelUtil.modiStrCell2(wsOne,1, 10,"√", wcf2);//企业类型内资
			 }else if ("2".equals(form.getQylx())){
				  ExcelUtil.modiStrCell2(wsOne,9, 10,"√", wcf2);//企业类型 港澳台
			 } else if ("2".equals(form.getQylx())){
			  ExcelUtil.modiStrCell2(wsOne,1, 11,"√", wcf2);//企业类型 外商
			}else if ("2".equals(form.getQylx())){
			  ExcelUtil.modiStrCell2(wsOne,9, 11,"√", wcf2);//企业类型 台资
			}
      
			 ExcelUtil.modiStrCell2(wsOne,2, 14, form.getQygyzb()==null?"":form.getQygyzb(), wcf2);//企业资本构成比例 国有
			 ExcelUtil.modiStrCell2(wsOne,11, 14, form.getQygrzb()==null?"":form.getQygrzb(), wcf2);//企业资本构成比例 个人
			 ExcelUtil.modiStrCell2(wsOne,2, 15, form.getQywszb()==null?"":form.getQywszb(), wcf2);//企业资本构成比例 外商
			 ExcelUtil.modiStrCell2(wsOne,13, 15, form.getQyhzzb()==null?"":form.getQyhzzb(), wcf2);//企业资本构成比例 港澳
			 
			 ExcelUtil.modiStrCell2(wsOne,1, 18, form.getXkContent()==null?"":form.getXkContent(), wcf1);//许可正内容
			 
			 ExcelUtil.modiStrCell2(wsOne,1, 20, form.getFzjg()==null?"":form.getFzjg(), wcf1);//许可发证机关
			 
			 ExcelUtil.modiStrCell2(wsOne,15, 21, form.getJdTel()==null?"":form.getJdTel(), wcf2);//监督电话
			 
			 ExcelUtil.modiStrCell2(wsOne,1, 23, form.getStartYear()==null?"":form.getStartYear(), wcf2);//许可正发证日期

			 ExcelUtil.modiStrCell2(wsOne,4, 23, form.getStartMonth()==null?"":form.getStartMonth(), wcf2);//许可正发证日期

			 ExcelUtil.modiStrCell2(wsOne,7, 23, form.getStartDay()==null?"":form.getStartDay(), wcf2);//许可正发证日期
      
			 ExcelUtil.modiStrCell2(wsOne,10, 23, form.getEndYear()==null?"":form.getEndYear(), wcf2);//许可正发证日期

			 ExcelUtil.modiStrCell2(wsOne,13, 23, form.getEndMonth()==null?"":form.getEndMonth(), wcf2);//许可正发证日期

			 ExcelUtil.modiStrCell2(wsOne,16, 23, form.getEndDay()==null?"":form.getEndDay(), wcf2);//许可正发证日期
      
			 ExcelUtil.modiStrCell2(wsOne,1, 25, form.getFzrq()==null?"":form.getFzrq(), wcf2);//许可正发证日期
			 ExcelUtil.modiStrCell2(wsOne,18, 25, form.getZsbh()==null?"":form.getZsbh(), wcf2);//许可正发证日期

             List list2 =new ArrayList();
             list2 = ywHwXminfoService.getFbXminfo(form.getId(), "shljqssj");
             if(StringUtils.isNotBlank(form.getXmnr1())){
                // Map<String, String> map2 =(Map<String, String>) list2.get(0);
                 String xmnr =form.getXmnr1();
                 xmnr = xmnr.replaceAll("<br>", "\r\n");
                 xmnr = xmnr.replaceAll("&nbsp;", " ");
                 xmnr +="\r\n  有效期限：";
                 String startday = form.getStartday1();
                 String endday = form.getEndday1();
                 if(startday!=null && startday.length()>0 && endday!=null && endday.length()>0){
                	 xmnr +="从"+startday+"到"+endday;
                 }
    			 ExcelUtil.modiStrCell2(wsOne,22, 2, xmnr==null?"":xmnr, wcfxmnr);//项目内容
                 String fzsj = form.getGzsj1();
                 String year="";
                 String month="";
                 String day="";
                 if(StringUtils.isNotBlank(fzsj) && fzsj.length()>=10){
                	 year = fzsj.substring(0, 4);
                	 month = fzsj.substring(5, 7);
                	 day = fzsj.substring(8, 10);
        			 ExcelUtil.modiStrCell2(wsOne,27, 5, year==null?"":year, wcfxmrq);//变更盖章年
        			 ExcelUtil.modiStrCell2(wsOne,29, 5, month==null?"":month, wcfxmrq);//变更盖章月
        			 ExcelUtil.modiStrCell2(wsOne,31, 5, day==null?"":day, wcfxmrq);//变更盖章日
                 }
                 if(StringUtils.isNotBlank(form.getXmnr2())){
                	 //map2 =(Map<String, String>) list2.get(1);
                	   xmnr =form.getXmnr2();
                     xmnr = xmnr.replaceAll("<br>", "\r\n");
                     xmnr = xmnr.replaceAll("&nbsp;", " ");
                     xmnr +="\r\n  有效期限：";
                      startday = form.getStartday2();
                      endday = form.getEndday2();
                     if(startday!=null && startday.length()>0 && endday!=null && endday.length()>0){
                    	 xmnr +="从"+startday+"到"+endday;
                     }
        			 ExcelUtil.modiStrCell2(wsOne,22, 8, xmnr==null?"":xmnr, wcfxmnr);//项目内容
                     fzsj =form.getGzsj2();
                     year="";
                     month="";
                     day="";
                     if(StringUtils.isNotBlank(fzsj) && fzsj.length()>=10 ){
                    	 year = fzsj.substring(0, 4);
                    	 month = fzsj.substring(5, 7);
                    	 day = fzsj.substring(8, 10);
            			 ExcelUtil.modiStrCell2(wsOne,27, 16, year==null?"":year, wcfxmrq);//变更盖章年
            			 ExcelUtil.modiStrCell2(wsOne,29, 16, month==null?"":month, wcfxmrq);//变更盖章月
            			 ExcelUtil.modiStrCell2(wsOne,31, 16, day==null?"":day, wcfxmrq);//变更盖章日
                     }
                 }
                 if(StringUtils.isNotBlank(fzsj)){
                	 //map2 =(Map<String, String>) list2.get(2);
                	 xmnr =form.getXmnr3();
                     xmnr = xmnr.replaceAll("<br>", "\r\n");
                     xmnr = xmnr.replaceAll("&nbsp;", " ");
                     xmnr +="\r\n  有效期限：";
                     startday = form.getStartday3();
                     endday = form.getEndday3();
                     if(startday!=null && startday.length()>0 && endday!=null && endday.length()>0){
                    	 xmnr +="从"+startday+"到"+endday;
                     }
        			 ExcelUtil.modiStrCell2(wsOne,22, 20, xmnr==null?"":xmnr, wcfxmnr);//项目内容
                     fzsj =form.getGzsj3();
                     year="";
                     month="";
                     day="";
                     if(StringUtils.isNotBlank(fzsj)&& fzsj.length()>=10){
                    	 year = fzsj.substring(0, 4);
                    	 month = fzsj.substring(5, 7);
                    	 day = fzsj.substring(8, 10);
            			 ExcelUtil.modiStrCell2(wsOne,27, 26, year==null?"":year, wcfxmrq);//变更盖章年
            			 ExcelUtil.modiStrCell2(wsOne,29, 26, month==null?"":month, wcfxmrq);//变更盖章月
            			 ExcelUtil.modiStrCell2(wsOne,31, 26, day==null?"":day, wcfxmrq);//变更盖章日
                     }
                 }
             }
             
		} catch (Exception e) {
			e.printStackTrace();
		} 
         
        
    }

    /**
     * 写副本第二页数据
     * @param wsOne
     * @param form
     */
    private void copyFbData2(WritableSheet wsOne, ShljqsForm form) {
    	 try {
			 WritableCellFormat wcf2=ExcelUtil.createCellFormat("宋体", 10, Alignment.CENTRE, VerticalAlignment.CENTRE,false);
			 WritableCellFormat wcfxmnr=ExcelUtil.createCellFormat("宋体", 10, Alignment.LEFT, VerticalAlignment.TOP,true);
			 wcf2.setLocked(false);
             List list2 =new ArrayList();
             list2 = ywHwXminfoService.getFbXminfo(form.getId(), "shljqssj");
             if(StringUtils.isNotBlank(form.getXmnr4())){
                 //Map<String, String> map2 =(Map<String, String>) list2.get(3);
                 String xmnr =form.getXmnr4();//map2.get("xmnr");
                 xmnr = xmnr.replaceAll("<br>", "\r\n");
                 xmnr = xmnr.replaceAll("&nbsp;", " ");
                 xmnr +="\r\n  有效期限：";
                 String startday = form.getStartday4();//map2.get("startday");
                 String endday =form.getEndday4();// map2.get("endday");
                 if(startday!=null && startday.length()>0 && endday!=null && endday.length()>0){
                	 xmnr +="从"+startday+"到"+endday;
                 }
    			 ExcelUtil.modiStrCell2(wsOne,0, 3, xmnr==null?"":xmnr, wcfxmnr);//项目内容
                 String fzsj =form.getGzsj4();// map2.get("gzsj");
                 String year="";
                 String month="";
                 String day="";
                 if(fzsj!=null && fzsj.length()>=10){
                	 year = fzsj.substring(0, 4);
                	 month = fzsj.substring(5, 7);
                	 day = fzsj.substring(8, 10);
        			 ExcelUtil.modiStrCell2(wsOne,10, 7, year==null?"":year, wcf2);//变更盖章年
        			 ExcelUtil.modiStrCell2(wsOne,13, 7, month==null?"":month, wcf2);//变更盖章月
        			 ExcelUtil.modiStrCell2(wsOne,15, 7, day==null?"":day, wcf2);//变更盖章日
                 }
                 if(StringUtils.isNotBlank(form.getXmnr5())){
                	 //map2 =(Map<String, String>) list2.get(4);
                	 xmnr =form.getXmnr5();//map2.get("xmnr");
                     xmnr = xmnr.replaceAll("<br>", "\r\n");
                     xmnr = xmnr.replaceAll("&nbsp;", " ");
                     xmnr +="\r\n  有效期限：";
                     startday = form.getStartday5();//map2.get("startday");
                     endday =form.getStartday6(); //map2.get("endday");
                     if(startday!=null && startday.length()>0 && endday!=null && endday.length()>0){
                    	 xmnr +="从"+startday+"到"+endday;
                     }
        			 ExcelUtil.modiStrCell2(wsOne,0, 9, xmnr==null?"":xmnr, wcfxmnr);//项目内容
                     fzsj = form.getGzsj5();//map2.get("gzsj");
                     year="";
                     month="";
                     day="";
                     if(fzsj!=null && fzsj.length()>=10){
                    	 year = fzsj.substring(0, 4);
                    	 month = fzsj.substring(5, 7);
                    	 day = fzsj.substring(8, 10);
            			 ExcelUtil.modiStrCell2(wsOne,10, 16, year==null?"":year, wcf2);//变更盖章年
            			 ExcelUtil.modiStrCell2(wsOne,13, 16, month==null?"":month, wcf2);//变更盖章月
            			 ExcelUtil.modiStrCell2(wsOne,15, 16, day==null?"":day, wcf2);//变更盖章日
                     }
                 }
                 if(StringUtils.isNotBlank(form.getXmnr6())){
                	// map2 =(Map<String, String>) list2.get(5);
                	 xmnr =form.getXmnr6();//.get("xmnr");
                     xmnr = xmnr.replaceAll("<br>", "\r\n");
                     xmnr = xmnr.replaceAll("&nbsp;", " ");
                     xmnr +="\r\n  有效期限：";
                     startday = form.getStartday6();//map2.get("startday");
                     endday = form.getEndday6();//map2.get("endday");
                     if(startday!=null && startday.length()>0 && endday!=null && endday.length()>0){
                    	 xmnr +="从"+startday+"到"+endday;
                     }
        			 ExcelUtil.modiStrCell2(wsOne,0, 19, xmnr==null?"":xmnr, wcfxmnr);//项目内容
                     fzsj = form.getGzsj6();//map2.get("gzsj");
                     year="";
                     month="";
                     day="";
                     if(fzsj!=null && fzsj.length()>=10){
                    	 year = fzsj.substring(0, 4);
                    	 month = fzsj.substring(5, 7);
                    	 day = fzsj.substring(8, 10);
            			 ExcelUtil.modiStrCell2(wsOne,10, 26, year==null?"":year, wcf2);//变更盖章年
            			 ExcelUtil.modiStrCell2(wsOne,13, 26, month==null?"":month, wcf2);//变更盖章月
            			 ExcelUtil.modiStrCell2(wsOne,15, 26, day==null?"":day, wcf2);//变更盖章日
                     }
                 }
             }
             
		} catch (Exception e) {
			e.printStackTrace();
		} 
         
        
    }
    /**
     * 写证书数据
     * @param wsOne
     * @param form
     */
    private void copyZsData(WritableSheet wsOne, ShljqsForm form) {      
        try {
            WritableCellFormat wcf=ExcelUtil.createCellFormat("宋体", 20, Alignment.LEFT, VerticalAlignment.CENTRE,false);
            WritableCellFormat wcf5=ExcelUtil.createCellFormat("宋体", 20, Alignment.RIGHT, VerticalAlignment.CENTRE,false);
            WritableCellFormat wcf1=ExcelUtil.createCellFormat("宋体", 20, Alignment.LEFT, VerticalAlignment.CENTRE,true);
            WritableCellFormat wcf2=ExcelUtil.createCellFormat("宋体", 18, Alignment.LEFT, VerticalAlignment.CENTRE,false);
            WritableCellFormat wcf3=ExcelUtil.createCellFormat("宋体", 18, Alignment.CENTRE, VerticalAlignment.CENTRE,false);
            WritableCellFormat wcf4=ExcelUtil.createCellFormat("宋体", 18, Alignment.RIGHT, VerticalAlignment.CENTRE,false);
            ExcelUtil.modiStrCell2(wsOne, 8,22, form.getZsbh()==null?"":form.getZsbh(), wcf);//编号
            ExcelUtil.modiStrCell2(wsOne, 0, 8, form.getSqdw()==null?"":form.getSqdw(), wcf);//申请单位
            ExcelUtil.modiStrCell2(wsOne, 10, 16, form.getFzjg(), wcf);//发证机关
            ExcelUtil.modiStrCell2(wsOne, 3, 20, form.getXkContent()==null?"":form.getXkContent(), wcf);//许可内容
            //ExcelUtil.modiStrCell2(wsOne, 3, 21, form.getProjectName()==null?"":form.getProjectName(), wcf);//项目名称
           // ExcelUtil.modiStrCell2(wsOne, 5, 14, form.getZsbh()==null?"":form.getZsbh(), wcf);//证书编号

            ExcelUtil.modiStrCell2(wsOne, 3, 23, form.getStartYear()==null?"":form.getStartYear(), wcf3);//开始-年
            ExcelUtil.modiStrCell2(wsOne, 5, 23, form.getStartMonth()==null?"":form.getStartMonth(), wcf3);//开始-月
            ExcelUtil.modiStrCell2(wsOne, 7, 23, form.getStartDay()==null?"":form.getStartDay(), wcf3);//开始-日
            ExcelUtil.modiStrCell2(wsOne, 10, 23, form.getEndYear()==null?"":form.getEndYear(), wcf3);//结束-年
            ExcelUtil.modiStrCell2(wsOne, 12, 23, form.getEndMonth()==null?"":form.getEndMonth(), wcf3);//结束-月
            ExcelUtil.modiStrCell2(wsOne, 14, 23, form.getEndDay()==null?"":form.getEndDay(), wcf3);//结束-日
            ExcelUtil.modiStrCell2(wsOne, 18, 23, form.getFzYear()==null?"":form.getFzYear(), wcf4);//发证-年
            ExcelUtil.modiStrCell2(wsOne, 20, 23, form.getFzMonth()==null?"":form.getFzMonth(), wcf3);//发证-月
            ExcelUtil.modiStrCell2(wsOne, 22, 23, form.getFzDay()==null?"":form.getFzDay(), wcf3);//发证-日
            ExcelUtil.modiStrCell2(wsOne, 21, 24, form.getJdTel()==null?"":form.getJdTel(), wcf2);//监督电话
            
            //wcf.setLocked(false);
            //wcf1.setLocked(false);
            //wcf2.setLocked(false);
                 
        } catch (Exception e) {
            e.printStackTrace();
            log.error("写入正式数据出现错误"+e);
        } 
        
    }
    /**
     * 生成后面的文件路径加上年月
     * @param realpath 定义的目录
     * @param fileNamesuffix 文件后缀名
     * @return
     */
    private String buildPath(String realpath,String fileName){
        String dateDir = GetFileName.getDirector();
        return realpath+"/"+dateDir+"/"+fileName;
        
    }


    
    
    /*
     * (non-Javadoc)
     * @see com.augurit.gzcgwsp.smartformCsdlwj.service.ISmartFormShljqsService#reSetForm(com.augurit.gzcgwsp.smartformCsdlwj.web.form.ShljqsForm)
     */
	public void reSetForm(ShljqsForm form) {
		this.csshljCzService.reSetForm(form);
	}
	
	//自动启动流程
	public void autoStartProc(ShljqsForm form,String templateCode){
		if(form != null && form.getId() != null){
			//测试需要保存一下
		//	this.save(form);
			
			//设置汇总字段
			form.setSqdw(form.getQymc());
			form.setSarq(form.getTbrq());
			
			//流程变量处理，默认将主业务对象作为form变量
			Map<String, Object> params = new HashMap<String, Object>();
			params.put(WfConstant.VAR_MASTER_ENTITY_ALIAS, form);
			
			//表示是自动启动流程,用来控制流程在"经办人员调查"环节是否启动人员分配事件
//			String areaCode = "4";
			String areaCode = form.getAreaCode();
			String userCode = this.findBoPlaceCode(Long.parseLong(areaCode), 98l);//98是【环卫科_经办人】角色ID 写死
			params.put("isAutoStartProc", "1");
			params.put("var_jbr",userCode);
			//获取该区的流程启动者
			String stratUser = wfServiceEX.getUser("hwk_ck", areaCode);
			WfBusInstanceTaskForm task = wfService.wfBusStart(templateCode, form, stratUser, params);
			String executionId =  processEngine.getHistoryService().createHistoryTaskQuery().taskId(task.getTaskInstDbid().toString()).uniqueResult().getExecutionId();
            processEngine.getExecutionService().jumpToActivity(executionId, "jbryskc");//跳到【经办人现场勘察、初审】 环节
		}
	}
	
	/**
	 * 
	 * @param id   区id
	 * @param roleId   角色id，通过代码写定
	 * @return
	 */
	private String findBoPlaceCode(Long id, Long roleId){
		return omOrgServiceEX.getUserByDistrictCodeAndRole(id.toString(), roleId);
	}


	public List getListById2(Long id,List list){
	    String sql="from YwHwShljqs ps where id="+id;
        return ywHwShljqsDao.find(sql,list);
    }
	

	public boolean checkData(String templateCode, String filename, Long id,
			Long qyid) {
		
		return this.csshljCzService.checkData(templateCode, filename, id, qyid);
	}

	/*
	 * (non-Javadoc)
	 * @see com.augurit.gzcgwsp.csshlj.service.IShljYsService#importData(com.augurit.gzcgwsp.csshlj.form.ShljYsForm, java.util.Map)
	 */
	public String importData(ShljqsForm form, Map map) {
		String result="";
		String contextpath=(String) map.get("contextPath");
		String templateCode=(String) map.get("templateCode");
		String ajid=(String) map.get("id");
		String qybh = (String) map.get("qybh");
	    
        //查询上传的材料
        String filepath=this.shljYsService.getSqbFilePath(map);
        filepath=(contextpath+filepath).replace("/", File.separator);
        File file=new File(filepath);
        if(StringUtils.isNotBlank(filepath)){
        	 Workbook wb;
        	  try {
				wb = Workbook.getWorkbook(file);
                  Sheet[] sheets=wb.getSheets();
                  int carinfo=0;
                  int cartools=0;
                  int placesite=0;
                  int transportdevice=0;
                  int execute=0;
                  for(int k=3;k<sheets.length;k++){
                	  if(StringUtils.isNotBlank(sheets[k].getName())){
                		  if(sheets[k].getName().indexOf("车辆情况说明")>-1){
                			  carinfo=k;
                		  }
                	  }
                	  if(StringUtils.isNotBlank(sheets[k].getName())){
                		  if(sheets[k].getName().indexOf("运输车辆工具情况说明")>-1){
                			  cartools=k;
                		  }
                		 
                	  }
                	  if(StringUtils.isNotBlank(sheets[k].getName())){
                		  if(sheets[k].getName().indexOf("停放场所情况")>-1){
                			  placesite=k;
                		  }
                		 
                	  }
                	  if(StringUtils.isNotBlank(sheets[k].getName())){
                		  if(sheets[k].getName().indexOf("运输装置")>-1){
                			  transportdevice=k;
                		  }
                		 
                	  }
                	  if(StringUtils.isNotBlank(sheets[k].getName())){
                		  if(sheets[k].getName().indexOf("执行情况说明")>-1){
                			  execute=k;
                		  }
                	  }
                  }
                  
                  
                  
                  result+=this.importInfoData(sheets[2], Long.parseLong(ajid));
                  InputStream is=new FileInputStream(filepath);
                  HSSFWorkbook hssfworkbook = new HSSFWorkbook(is);// 将is流实例到
                  //多个车辆情况说明的情况
                  for(int k=3;k<sheets.length;k++){
                	  if(StringUtils.isNotBlank(sheets[k].getName())){
                		  if(sheets[k].getName().indexOf("车辆情况说明")>-1){//可能出现多个车辆情况说明
                			  ywHwLyqsclqksmService.parseYwHwLyqsclqksm(hssfworkbook.getSheetAt(k), Long.parseLong(qybh), Long.parseLong(ajid),templateCode,k);//导入 生活垃圾清扫车辆（清捞船只）情况说明
                          }
                	  }
                  ywHwYsclgjService.parseYwHwYsclgj(hssfworkbook.getSheetAt(cartools),  Long.parseLong(qybh), Long.parseLong(ajid), templateCode);
                  ywHwCltfcsqkService.parseYwHwCltfcsqk(hssfworkbook.getSheetAt(placesite),  Long.parseLong(qybh), Long.parseLong(ajid),templateCode);//导入 办公和车辆停放场所情况
                  ywHwYszzService.parseYwHwYszz(hssfworkbook.getSheetAt(transportdevice),  Long.parseLong(qybh), Long.parseLong(ajid),templateCode);
                  ywHwZxqksmService.parseYwHwZxqksm(hssfworkbook.getSheetAt(execute),  Long.parseLong(qybh), Long.parseLong(ajid), templateCode);
                   HSSFRow hssfrow = hssfworkbook.getSheetAt(2).getRow(hssfworkbook.getSheetAt(2).getPhysicalNumberOfRows()-1);
                  if(hssfrow!=null){
                	  String ysgjjsxn;
                	  if (hssfrow.getCell((short) 0) == null) {
                		  ysgjjsxn = "";
                	  } else if (hssfrow.getCell((short) 0).getCellType() == 0) {
                		  ysgjjsxn = new Double(hssfrow.getCell((short) 0).getNumericCellValue()).toString();
                	  } else {// 如果EXCEL表格中的数据类型为字符串型
                		  ysgjjsxn = hssfrow.getCell((short) 0).getStringCellValue().trim();
                	  }
                	  if(!StringUtils.isEmpty(ysgjjsxn)){
                		  String sql = "Update HW_SHLJQS_V1 SET YSGJJSXN ='"
                			  + ysgjjsxn 
                			  + "' where ID = " + Long.parseLong(ajid);
                		  smartDao.executeSql(sql);
                	  }
                     }
                  }
	        } catch (Exception e) {
	        	 log.error("收件材料错误"+e);
				  result+="收件材料没有符合条件的文件\n";
		    }
        }else{
            result+="收件材料没有符合条件的文件\n";
            
        }
        
        map.put("filename", "项目情况登记表");
        filepath=this.shljYsService.getSqbFilePath(map);
        filepath=(contextpath+filepath).replace("/", File.separator);
        file=new File(filepath);
        if(StringUtils.isNotBlank(filepath)){
        	try{
            	InputStream is=new FileInputStream(filepath);
            	ywHwXminfoService.importExcel(is, Long.parseLong(qybh), Long.parseLong(ajid),templateCode);
        	} catch (Exception e) {
        		 log.error("收件材料错误"+e);
				  result+="收件材料没有符合条件的文件\n";
		    }
        }
        
		return null;
	}
	
	 /**
     * 功能:导入 处置服务行政许可申请书导入模板.xls 入库操作<br>
     * 参数:<br>
     * 返回:<br>
     * 作者:庄国坤<br>
     * 说明:<br>
     */
    public String importInfoData(Sheet sheet ,long ajid) throws Exception {
    	  String rt="";
          try{
        	  //解释sheet
              int offsetRow = 0, offsetCol=-1,row = 0;//如果行列有变化,只需修改此偏移量即可.by zhgk 2012/12/17
              row=1+offsetRow;

              String qs = ExcelUtil.readData(sheet,1,0);
              String sj = ExcelUtil.readData(sheet, 2, 0);
              String ys = ExcelUtil.readData(sheet, 3, 0);
    /*          String applyName = ExcelUtil.readData(sheet,1+offsetCol,
                      row)
                      + ",";
              applyName += ExcelUtil.readData(sheet, 2+offsetCol, row)
                      + ",";
              applyName += ExcelUtil.readData(sheet, 3+offsetCol, row)
                      + ",";
              if (applyName != null) {
                  applyName = applyName.substring(0, applyName.length() - 1);
              }*/
              
              row++;
              String companyName = ExcelUtil.readData(sheet, offsetCol + 1,
                      row);
              String orgCodeName = ExcelUtil.readData(sheet,3,
                      1);

              row++;
              String lawPerson= ExcelUtil.readData(sheet, 1,
                     2);
              
              row++;
              String bgzs  = ExcelUtil.readData(sheet,  1,
                     4);//办公住所
              String regCode = ExcelUtil.readData(sheet, 3,
                      2);
              
              row++;
              String telphone = ExcelUtil.readData(sheet,1,
                     3);
              String faxCode = ExcelUtil.readData(sheet, offsetCol + 4,
                      3); 
              
              row++;
              String lawPersonEmail = ExcelUtil.readData(sheet, offsetCol + 2,
                     7);
              String postCode = ExcelUtil.readData(sheet, offsetCol + 4,
                      7); 

              row++;
              String projectName = ExcelUtil.readData(sheet, offsetCol + 1,
                      row); 
              
              row++;
              String regMoney = ExcelUtil.readData(sheet, offsetCol + 2,
                     4); 
              

              row++;
              String agentMan = ExcelUtil.readData(sheet, offsetCol + 2,
                     6); 

              row++;
              
              String agentManTel = ExcelUtil.readData(sheet, offsetCol + 2,
                     9); 
              
              row++;
              String agentManFax = ExcelUtil.readData(sheet, offsetCol + 2,
                     10);
              
              row++;
              String agentManEmail = ExcelUtil.readData(sheet, offsetCol + 2,
                     11); 
              String remark = ExcelUtil.readData(sheet, 0,
                      12); 
              YwHwShljqs obj;
              List list =new ArrayList();
              list=getListById2(ajid,list);
              if(list!=null && list.size()>0){
            	  obj=(YwHwShljqs) list.get(0);
              }else{

                  obj = new YwHwShljqs();
              }
      //        obj.setSqnrqs(applyName);
              if(qs!=null && qs.equals("清扫")){
            	  obj.setFwnrqs("0");
              }else{
            	  obj.setFwnrqs("1");
              }
              if(sj!=null && sj.equals("收集")){
            	  obj.setFwnrqs("0");
              }else{
            	  obj.setFwnrqs("1");
              }
              if(ys!=null && ys.equals("运输")){
            	  obj.setFwnrqs("0");
              }else{
            	  obj.setFwnrqs("1");
              }
              //obj.setBgzs(bgzs);
              obj.setZzjgdm(orgCodeName);
              if(StringUtils.isNotBlank(agentMan)){
            	  
            	  	   agentMan=agentMan.replace("持法人代表委托书","");
            	  	   agentMan=agentMan.replace("(附件3)", "").trim();
            		   obj.setWts(agentMan);
              }
              if(StringUtils.isBlank(agentMan)){
            	  agentMan= ExcelUtil.readData(sheet,1,8); 
            	  obj.setWts(agentMan);
              }
              if(StringUtils.isNotBlank(regMoney)){
            	  regMoney=regMoney.replace("万元","");
            	  regMoney=regMoney.replace("(", "").replace(")","").replace("（", "").replace("）", "");
            	  
              }
              if(StringUtils.isNotBlank(remark)){
            	  remark=remark.replace("备注：","").trim();
            	  
              }
              
              
              obj.setYyzzzch(regCode);
              obj.setLxdh(telphone);
              //obj.setXmmc(projectName);
              obj.setCzdh(faxCode);
              obj.setEmail(lawPersonEmail);
              obj.setYzbm(postCode);
              obj.setZczb(regMoney);
              obj.setFrdb(lawPerson);
              obj.setLxdh2(agentManTel);
              obj.setEmail2(agentManEmail);
              //张军 todo
              obj.setCzdh2(agentManFax);//set移动电话(agentManMobile);//此处不知是哪个字段,张军检查
              obj.setBz(remark);
       
          this.ywHwShljqsDao.save(obj); //请修改此处DAO调用      
          
          if(StringUtils.isNotBlank(obj.getQybh())){
  			YwComQyxxForm form=ywComQyxxService.get(Long.valueOf(obj.getQybh()));
  			form.setSqdw(obj.getSqdw());
  			form.setFddbr(obj.getFrdb());
  			form.setCz(faxCode);
  			form.setZczj(regMoney);
  			form.setEmail(obj.getEmail());
  			form.setPost(obj.getYzbm());
  			form.setQyphone(telphone);
  			form.setAddress(obj.getBgzs());
  			 ywComQyxxService.updateYwComQyxx(form);
  		}
          
          }catch(Exception ee){
        	  ee.printStackTrace();
              rt="导入服务内容申请Excel文件时出错";
          }
          return rt;
    }
    
    /**
     * 生成证书编号
     */
	public String createZsbh(Map map,Long id) {
		String tablename=(String) map.get("tablename");
		String zsname=(String) map.get("zsname");
		
		String sql= "select * from "+tablename+" where id="+id;
		List list=this.ywHwShljqsDao.getListById(sql);
		if(list!=null && list.size()>0){
			Map dataMap=(Map) list.get(0);
			String zsbh=(String) dataMap.get(zsname);
			String area=(String) map.get("xmqy");
			if(StringUtils.isBlank(zsbh)){
				//开始加入证书编号
				String zsnum=this.buildZsbh(tablename, area);
				String updatesql=" update "+tablename+" set fzh='"+zsnum+"' where id="+id;
				ywHwShljqsDao.updateDateBase(updatesql);
			}
		}
		
		return null;
	}
	
	/**
	 * 生成证书
	 * @return
	 */
	public String buildZsbh(String tablename,String area){
		if(StringUtils.isBlank(area) || "null".equals(area)){
			area="00";//如果空就是00
		}
		String sql="select count(id) as countnum from "+tablename;
		List list=ywHwShljqsDao.queryForList(sql);
		Map map=(Map) list.get(0);
		String numstr=(String) map.get("countnum");
		if(StringUtils.isNotBlank(numstr)){
			Long num=Long.valueOf(numstr)+1;
			int k=4-String.valueOf(num).length();
			String prefix="";
			for(int i=1;i<=k;i++){
				prefix+="0";
			}
			return area+prefix+String.valueOf(num);
		}else{
			return area+"0001";
		}
	}
	
	/**
	 * 转换form
	 * @param result
	 * @return
	 */
		private List<ShljqsForm> convertToList(List<YwHwShljqs> result) {
			List<ShljqsForm> list=new ArrayList<ShljqsForm>();
		    if(result!=null && result.size()>0){
		    	ShljqsForm form=null;
		    	for(YwHwShljqs objs:result){
		    		form=new ShljqsForm();
		    		String sqdw=(String)objs.getQymc();
		    		String frdb=(String)objs.getFrdb();
		    		String lxdh=(String)objs.getLxdh2();
		    		String startdate=objs.getJysjsstr();//发证开始时间
		    		String enddate=objs.getJysjestr();//发证结束时间
		    		String address=objs.getBgzs();//办公住所
		    		
		    		//获取车辆经营的号码
		    		String carNo=getCheckCar(objs.getId(),"shljqssj");
		     		if(StringUtils.isBlank(startdate)){
		    			startdate=DateUtilsEX.getCurYear()+"年"+DateUtilsEX.getCurMonth()+"月"+DateUtilsEX.getCurDay()+"日";
		    		}
		    		if(StringUtils.isBlank(enddate)){
		    			enddate=DateUtilsEX.getCurYear()+"年"+DateUtilsEX.getCurMonth()+"月"+DateUtilsEX.getCurDay()+"日";
		    		}
		    		form.setId(objs.getId());
		    		form.setValiddate(startdate+"~~"+enddate);
		    		form.setValidstarttime(startdate==null?"":startdate);
		    		form.setValidendtime(enddate==null?"":enddate);
		    		form.setCheckcar(carNo);
		    		form.setJyscale(carNo);
		    		form.setSsAddr(address==null?"":address);
		    		form.setFrdb(frdb==null?"":frdb);
		    		form.setAddress(address==null?"":address);
		    		form.setSqdw(sqdw==null?"":sqdw);
		    		form.setCompanyphone(lxdh==null?"":lxdh);
		
		    		form.setCbyw("广州市（陆域）城市生活垃圾经营性清扫、收集、运输服务");
		    		list.add(form);
		    	}
				
		    }
			return list;
		}
		
		//---获取待在办出证数据--
		public Page<ShljqsForm> getDbData(Page<ShljqsForm> page,Map map){
			// 建立新的分页对象
			Page pg = PageUtils.newPageInstance(page);
			String hql=getHql(map);
			Map<String, Object> values = new HashMap();
			smartFormShljqsDao.findPage(pg, hql,values);
			// 转换为Form对象列表并赋值到原分页对象中
			List<ShljqsForm> list = convertToList(pg.getResult());
			PageUtils.copy(pg, list, page);
			return page;
		}
		
		/**
		 *查询待办的sql
		 * @param map
		 * @return
		 */
		private String getHql(Map map){
			StringBuffer hql = new StringBuffer();
			String startdate=(String)map.get("startdate");
			String qyname=(String)map.get("qyname");
			String enddate=(String)map.get("enddate");
			String username=(String) map.get("username");
			if(StringUtils.isNotBlank(enddate)){
				String[] enddates=enddate.split("-");
				if(enddates.length==3){
					if(enddates[1].length()<2){//如果日期是2012-5-12这种格式
						enddate=enddates[0]+"-0"+enddates[1]+"-"+enddates[2];
					}
				}
			}
			if(StringUtils.isBlank(enddate)){//如果日期为空就为当前日期
				enddate=DateUtilsEX.dateFormate(new Date(),"yyyy-MM-dd");
				enddate+=" 23:59:59";
			}else if(enddate.length()>=10){
				enddate=enddate.substring(0,10)+" 23:59:59";
			}
			if(StringUtils.isBlank(startdate)){//如果日期为空显示3天前的数据
				startdate=DateUtilsEX.getDateByDay(new Date(),-3,"yyyy-MM-dd");
			}else if(startdate.length()>=10){
				startdate=startdate.substring(0,10);
			}
			hql.append(" select qs ");
			hql.append(" from Jbpm4HistTask task, Jbpm4HistProcinst proc, WfBusInstance inst,");
			hql.append(" YwHwShljqs qs ");
			hql.append(" where task.procInstId = proc.procInstId and proc.procInstId = inst.procInstId ");
			hql.append(" and inst.masterEntityKey=qs.id and inst.masterEntity='YwHwShljqs' ");
			hql.append(" and proc.state='active' ");
			hql.append(" and task.state='open'" );
			hql.append("and task.assignee='"+username+"'");
			hql.append(" and task.activityName='gzryczh'");  //---办证环节
		
			if(StringUtils.isNotBlank(qyname)){
				hql.append(" and cz.qymc like '%"+qyname+"%'");
			}
			if(StringUtils.isNotBlank(startdate)){
				hql.append(" and task.signTime>=to_date('"+startdate+"','yyyy-mm-dd')");
			}
			if(StringUtils.isNotBlank(enddate)){
				hql.append(" and task.signTime<=to_date('"+enddate+"','yyyy-mm-dd HH24:mi:ss')");
			}
			
			return hql.toString();
		}
		/*
		 *导出时查询待办的数据 (non-Javadoc)
		 * @see com.augurit.gzcgwsp.csshlj.service.IShljYsService#getDbDatas(java.util.Map)
		 */
		public List<Object[]> getDbDatas(Map map) {
			String sql=getHql(map);
			List<YwHwShljqs> list=smartFormShljqsDao.find(sql);
			List<Object[]> datas=new ArrayList<Object[]>();
			for(YwHwShljqs obj:list){
				Object[] objs=new Object[9];
				String sqdw=(String)obj.getQymc();
	    		String frdb=(String)obj.getFrdb();
	    		String lxdh=(String)obj.getLxdh2();
	    		String startdate=obj.getJysjsstr();//发证开始时间
	    		String enddate=obj.getJysjestr();//发证结束时间
	    		String address=obj.getBgzs();//办公住所
	    		//获取车辆经营的号码
	    		String carNo=getCheckCar(obj.getId(),"shljqssj");
	    		objs[0]=obj.getId();
	    		objs[1]=sqdw;
	    		objs[2]=frdb;
	    		objs[3]=lxdh;
	    		objs[4]=startdate;
	    		objs[5]=enddate;
	    		objs[6]=carNo;
	    		objs[7]=address;
	    		datas.add(objs);
			}
			return datas;
		}
		
		/**
		 * 循环获取车牌号
		 * @param id
		 * @param tempcode
		 * @return
		 */
		private String getCheckCar(Long id, String tempcode) {
			List<YwHwYsclgj> list=ywHwYsclgjService.getCheckCar(id, tempcode);
			String carNo="";
			for(YwHwYsclgj entity:list){
				carNo+=entity.getXh()+"、";
			}
			if(StringUtils.isNotBlank(carNo)){
				carNo=carNo.substring(0, carNo.length()-1);
			}
			return carNo;
		}
		
		/*
		 * 保存表单(non-Javadoc)
		 * @see com.augurit.gzcgwsp.smartformCsdlwj.service.ISmartFormShljqsService#wfBusSave(javax.servlet.http.HttpServletRequest, com.augurit.gzcgwsp.smartformCsdlwj.web.form.ShljqsForm, java.util.Map, java.lang.String)
		 */
		public WfBusInstanceTaskForm wfBusSave(HttpServletRequest request,
				ShljqsForm form, Map map, OmUserForm userForm) {
			if(form.getTbrq()==null){
				if(form.getTbrq2()!=null){
					//form.setTbrq(DateUtilsEX.getStringToDate(form.getTbrq2()));
				}
			}
			
			WfBusInstanceTaskForm task = wfSupportService
			.wfBusSave(request);
			if(task != null && task.getMasterEntityKey()!=null){
				//很难找出填表日期为什么没保存到
				String sql="select tbrq from HW_SHLJQS_V1 where id="+task.getMasterEntityKey();
				List list=this.smartFormShljqsDao.queryForList(sql);
				if(list!=null){
					Map maps=(Map) list.get(0);
					String date=(String) maps.get("tbrq");
					if(StringUtils.isBlank(date)){
						String datestr=DateUtilsEX.dateFormate(new Date(), "yyyy-MM-dd");
						String updatesql=" update HW_SHLJQS_V1 set tbrq=to_date('"+datestr+"','yyyy-MM-dd') where id="+task.getMasterEntityKey();
						this.smartFormShljqsDao.updateDateBase(updatesql);
					}
				}
			}
			if(task==null)
				return null;
				
				String entityKey = task.getMasterEntityKey();
				String ysl = (String) map.get("hw_shljqs_ysl");
				String sqdw = (String) map.get("hw_shljqs_qymc"); // 申请单位
				LoginUserForm user=(LoginUserForm)request.getSession().
			     getAttribute(WebContextUtils.SES_LOGIN_USER);
				String acceptNo = updateAcceptNoAndSumary(entityKey, sqdw, ysl,userForm,user); // 更新入受理号以及汇总字段
				Long id = null;
				if (task != null && task.getMasterEntityKey() != null) {
					id = Long.valueOf(task.getMasterEntityKey());
				}
				
				form.setId(id);
				task.setMessage(acceptNo); //设置受理编号
				if (ysl.equals("1")) { // 更新预受理状态
					changeYslState(id, 2l,null);
				}
				form.setId(id);
				
				//构造map
				String qyid=(String) map.get("hw_shljqs_qybh");//企业id
				String frdb=(String) map.get("hw_shljqs_frdb");//法人代表
				String yyzzzch=(String) map.get("hw_shljqs_yyzzzch");//营业注册号码
				String tel=(String) map.get("hw_shljqs_lxdh");//联系电话
				String regmoney=(String) map.get("hw_shljqs_zczb");//注册资金
				String fax=(String) map.get("hw_shljqs_czdh");//传真
				String email=(String) map.get("hw_shljqs_email");//电子邮箱
				String post=(String) map.get("hw_shljqs_yzbm");//邮编
				String address=(String) map.get("hw_shljqs_bgzs");//办公住所
				String zsbh=(String) map.get("hw_shljqs_fzh");//办公住所
				map.put("qyid", qyid);
				map.put("tel",tel);
				map.put("sqdw",sqdw);
				map.put("frdb",frdb);
				map.put("yyzzzch", yyzzzch);
				map.put("regmoney", regmoney);
				map.put("fax", fax);
				map.put("email", email);
				map.put("post", post);
				map.put("address",address);
				if(zsbh!=null && zsbh.length()>0){
					map.put("zsbh",zsbh);
				}
				Long qybh=csshljCzService.saveEnterpriseInfo("shljqssj", map);
				if(qybh!=null){
					form.setQybh(String.valueOf(qybh));
					updateEntityByQyId(qybh,id);//设置企业编号
				}
				
				return task;
		}
		
		/**
		 * 更新受理号 汇总字段
		 * 
		 * @param entityId
		 * @return
		 * @throws ParseException
		 */
		private String updateAcceptNoAndSumary(String entityId, String sqdw,
				String ysl,OmUserForm userForm,LoginUserForm user) {
			
			String acceptNo = "";

			// ====================判断受理号是否存在，更新受理号和汇总字段================
			if (entityId != null && entityId.trim().length() > 0) {
				String isExist = "select ACCEPT_NO from HW_SHLJQS_V1 where id = "
						+ entityId;
				List list = smartDao.getResultList(isExist);
				if (list != null) {
					Object obj = list.get(0);
					String s = (String) obj;
					if (s == null || s.trim().length() <= 0) {

						// ===================生成受理编号，更新受理编号开始========
//						OaDocCodeForm doccodeForm = docCodeService.get(10L);
//						acceptNo = CommonUtils.convertSeqToAcceptNo(doccodeForm
//								.getSeq());
//						docCodeService.updateForAddSeq(doccodeForm.getId());
						//生成政务中心统一查询编号 开始
						Map<String,String> serialNoAndPasswordMap = null;
			        	serialNoAndPasswordMap = ywMtbjlshInfoService.getSerialNoAndPassword("0");			        	
			        	String serialNo = serialNoAndPasswordMap.get("serialNo");
			        	String password = serialNoAndPasswordMap.get("password");
			        	//生成政务中心统一查询编号 结束
			        	acceptNo = serialNo;
						String sql = "Update HW_SHLJQS_V1 SET ACCEPT_NO ='"
								+ serialNo
								+ "',SERIAL_NO='"
								+ serialNo
								+"',PASSWORD='"
								+ password
								+ "' , SJR = '"
								+ userForm.getUserName()
								+ "' where ID = " + entityId;
						smartDao.executeSql(sql);
						// ==================生成受理编号，更新受理编号结束==========

						// 更新汇总
						WfBusInstance entity = wfBusInstanceService
								.getByMasterEntityAndKey("YwHwShljqs", entityId);
						entity.setBusMemo1(sqdw);
						entity.setBusMemo3(serialNo);
						entity.setBusMemo4("广州市（陆域）城市生活垃圾经营性清扫、收集、运输服务");
						entity.setBusDate2(new Date());
						WfBusInstanceForm form = WfBusInstanceConvertor
								.convertVoToForm(entity);
						String orgName=user.getOrg().getOrgName();
						if(StringUtils.isNotBlank(orgName)){
							form.setBusMemo2(orgName.substring(0,3));	
						}
						wfBusInstanceService.save(form);

					} else if ((s != null && s.trim().length() > 0) && ysl.equals("1")) { // 预受理状态下，更新汇总字段
						//设置收件人  开始
						String sql = "Update HW_SHLJQS_V1 SET SJR = '"
							+ userForm.getUserName()
							+ "' where ID = " + entityId;
						smartDao.executeSql(sql);
						//设置收件人  结束
						acceptNo = s;
						WfBusInstance entity = wfBusInstanceService
								.getByMasterEntityAndKey("YwHwShljqs", entityId);
						entity.setBusMemo1(sqdw);
						entity.setBusMemo3(acceptNo);
						entity.setBusMemo4("广州市（陆域）城市生活垃圾经营性清扫、收集、运输服务");
						entity.setBusDate2(new Date());
						WfBusInstanceForm form = WfBusInstanceConvertor
								.convertVoToForm(entity);
						if(user!=null &&user.getOrg()!=null
								&& StringUtils.isNotBlank(user.getOrg().getOrgName())){
							String orgName=user.getOrg().getOrgName();
							String area=orgName.substring(0,3);//截取区域
							form.setBusMemo2(area);
						}
						
						form.setBusMemo2(userForm.getUserCode().substring(0, 2));
						wfBusInstanceService.save(form);
					} else {
						acceptNo = s;
					}
				}
			}
			return acceptNo;
		}
		
		public void changeYslState(Long id,Long state,String yslThyy) {
	    	StringBuffer sql = new StringBuffer();
	    	sql.append("update YwHwShljqs t set t.ysl='"+state+"' ");
	    	if(StringUtils.isNotBlank(yslThyy)){
	    		sql.append(" ,t.yslThyy='"+yslThyy+"'");
	    	}
	    	sql.append(" where t.id="+id);
	    	ywHwShljqsDao.getSession().createQuery(sql.toString()).executeUpdate();
	    	System.out.println("陆域收件");
	    }
		
		/**
		 * 设置企业id
		 * @param qybh
		 * @param id
		 */
		private void updateEntityByQyId(Long qybh, Long id) {
			String sql=" update HW_SHLJQS_V1 set QYBH="+qybh +" where id="+id ;
			this.smartFormShljqsDao.updateDateBase(sql);
		}
		
		public String wfBusYslTuih(ShljqsForm form,LoginUserForm loginUser) throws Exception {
	    	String  loginUserName = loginUser.getUser().getUserName();
	    	WfBusInstanceTaskForm taskForm = new WfBusInstanceTaskForm();
			taskForm.setHandleComments("资料不全，不予受理。");
			//把审批状态数据保存到ywWebserviceInfo ，交换给方欣
			ywWebserviceInfoService.saveYwWebserviceInfo(form.getTbrq(), form.getAcceptNo(), form.getCbyw(), form.getJbrxm(), form.getSjr(), form.getSqdw(), 
					form.getBusinessCode(), form.getApprovalNo(), loginUserName, loginUser.getOrg().getOrgName(), "ysl", new Date(), false, "预受理", taskForm);
//			System.out.println("form.getYslThyy() = "+java.net.URLDecoder.decode(form.getYslThyy(),"UTF-8"));
			this.changeYslState(form.getId(), 0L,taskForm.getHandleComments());
			
			//（网办）交换到市民网页
			Map map=exchangeStateService.buildMap(loginUser, null, form.getId().toString(), form.getTemplateCode(), false);
			String durationExpression = wfServiceEX.getDurationExpressionByTemplateCode(form.getTemplateCode());
			ywWebserviceForWbService.setValueAndSaveYwWebserviceForWb(loginUserName,form.getTemplateCode(),
					form.getId().toString(),durationExpression,"001",taskForm.getHandleComments(), map);
	    	return null;
	    }

		/*
		 * (non-Javadoc)
		 * @see com.augurit.gzcgwsp.smartformCsdlwj.service.ISmartFormShljqsService#getArea(com.augurit.gzcgwsp.smartformCsdlwj.web.form.ShljqsForm)
		 */
		@Override
		public String getArea(ShljqsForm form) {
			String sql="select  t.bus_memo2 from wf_bus_instance t where t.master_entity='YwHwShljqs' and t.master_entity_key='"+form.getId()+"'";
			String area="";
			List list=this.smartFormShljqsDao.getListById(sql);
			if(list!=null &&list.size()>0){
				Map map=(Map) list.get(0);
				area=(String) map.get("bus_memo2");
			}
			return area;
		}
		
		/**
		 * 保存收件通知书材料 
		 * @return
		 * @throws Exception
		 */
		public String saveSjtzs(String [] checkedIds,String context,ShljqsForm form,LoginUserForm user) throws Exception {
			String checkedIdsStr = "";
			//先把以前的数据删掉
			ywComSjtzsScclService.deleteByAcceptNoAndAjidAndTemplateCode(form.getAcceptNo(), form.getId(), form.getTemplateCode());
			if(checkedIds != null){
				for(int i=0;i<checkedIds.length;i++){
					String checkedId = checkedIds[i];
					checkedIdsStr = checkedIdsStr +"===" + checkedId;
					YwComSjcllistForm ywComSjcllistForm = ywComSjcllistService.get(Long.parseLong(checkedId));
					YwComSjtzsScclForm ywComSjtzsScclForm = new YwComSjtzsScclForm();
					ywComSjtzsScclForm.setAcceptNo(form.getAcceptNo());
					ywComSjtzsScclForm.setAjid(form.getId());
					ywComSjtzsScclForm.setTplcode(form.getTemplateCode());
					ywComSjtzsScclForm.setTitle(ywComSjcllistForm.getTitle());
					ywComSjtzsScclForm.setClid(Long.parseLong(checkedId));
					ywComSjtzsScclService.save(ywComSjtzsScclForm);
				}
			}
			List<YwComSjtzsSccl> list=ywComSjtzsScclService.getdataByNo(form.getAcceptNo());
			//查询收件材料
			 YwComSjcllistForm sjclListForm=new YwComSjcllistForm();
		     sjclListForm.setAjid(form.getId());
		     sjclListForm.setTplcode(form.getTemplateCode());
		     List<YwComSjcllistForm> sjclList = ywComSjcllistService.getList(sjclListForm);
		     List<Map<String,String>> sjcl=new ArrayList<Map<String,String>>();
             for(YwComSjcllistForm listform:sjclList){
            	 Map<String,String> map=new HashMap<String,String>();
            	 map.put("title", listform.getTitle());
            	 map.put("fs", String.valueOf(listform.getFyjs()+listform.getYjs()));
            	 map.put("fyjs", String.valueOf(listform.getFyjs()));
            	 for(YwComSjtzsSccl sccl:list){
            		 if(sccl.getTitle().equals(listform.getTitle())){
            			 map.put("zzcl", "√");
            			 continue;
            		 }
            	 }
            	 sjcl.add(map);
             }
			this.printSjtzs(context, form, user,sjcl);
			return null;
		}
		
		/**
		 * 打印收件通知书
		 * @param inpath
		 * @param tempOutPath
		 * @param context
		 * @param ywComSjcllistForm
		 * @throws Exception 
		 */
		public String printSjtzs(String context, ShljqsForm form, LoginUserForm user,List<Map<String,String>> list) {
		    String tempOutPath="/printdoc/shljqssj/";
		    String fileName = form.getTemplateCode() + "-" + "sjtzs" + "-" + form.getAcceptNo() + ".doc";
		    String returnpath=tempOutPath+fileName;
		    String filepath=context+"/"+returnpath;
		    filepath=filepath.replace("/",File.separator);
		    String outdir=filepath.substring(0,filepath.lastIndexOf(File.separator));
		    File file=new File(outdir);
		    if(!file.exists()){
		        file.mkdirs();
		    }
		    //开始写文件
		    String userName=user.getUser().getUserName();
	    	String orgname=user.getOrg().getOrgName();
		    try {
				writeDoc(context, form, filepath,list,userName,orgname);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		    this.saveYwPrintDoc(form.getTemplateCode(), "sjtzs",form.getId(), returnpath, 972l, userName);
		    return returnpath;
		}
		
		
		/**
		 * 写word
		 * @param context
		 * @param from
		 * @return
		 * @throws Exception 
		 */
		private void writeDoc(String context,ShljqsForm form,String filepath,
				List<Map<String,String>> sjcl,String username,String orgname) throws Exception{
		
			Document document=ItextWordUtil.ceateDocument(PageSize.A4);
	    	ItextWordUtil.openDocument(document,filepath);
	    	BaseFont bfChinese = BaseFont.createFont("STSongStd-Light",   
	                "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); 
			 int width[] = {20,20};   
		    	Table table=ItextWordUtil.creatTeable(3,2,width,new Color(0, 125, 255));
		    	int width1[] = {10,30,5,5,5};
		    	Table table1=ItextWordUtil.creatTeable(sjcl.size(),5,width1,new Color(0, 125, 255));
		    	Font fontChinese = new Font(bfChinese, 10); 
		    	Font font = DocStyleUtils.setFontStyle("华文中宋", 14f, Font.BOLD);   
		    	StringBuffer contentSb = new StringBuffer();   
		        contentSb.append("你单位向广州市城市管理委员会提出的关于的申请，提交材料明细如下：");   
		        Paragraph blankRow = new Paragraph(18f, " ", fontChinese);   
		        Paragraph bodyPar = DocStyleUtils.setParagraphStyle(contentSb.toString(), fontChinese, 32f, 18f);   
		        StringBuffer contentSb1 = new StringBuffer();   
		        contentSb1.append("依据《中华人民共和国行政许可法》及相关法律法规规定，本机关将在 5  个工作日内做出是否受理决定。");   
		        Paragraph bodyPar1 = DocStyleUtils.setParagraphStyle(contentSb1.toString(), fontChinese, 32f, 18f);   
		        StringBuffer contentSb2 = new StringBuffer();   
		        StringBuffer contentSb3 = new StringBuffer(); 
		        StringBuffer contentSb4 = new StringBuffer();  
		        StringBuffer contentSb5 = new StringBuffer();  
		        StringBuffer contentSb6 = new StringBuffer(); 
		        StringBuffer contentSb7 = new StringBuffer(); 
		        StringBuffer sqdwstr = new StringBuffer();
		        StringBuffer title = new StringBuffer();   
		        sqdwstr.append(form.getSqdw()+"："); 
		        title.append("收件通知书");   
		        Paragraph titlepar = DocStyleUtils.setParagraphStyle(title.toString(), font, 0f, 18f,Element.ALIGN_CENTER);   
		        contentSb2.append("提示：1. 本通知书不作为是否受理行政许可申请的依据。");   
		        Paragraph bodyPar2 = DocStyleUtils.setParagraphStyle(contentSb2.toString(), fontChinese, 0f, 18f);   
		        contentSb3.append("2. 换领受理通知书时需出示本通知书和领取人身份证明。");   
		        Paragraph bodyPar3= DocStyleUtils.setParagraphStyle(contentSb3.toString(), fontChinese, 34f, 18f);   
		        contentSb4.append("3. 本窗口联系电话：020—");   
		        Paragraph bodyPar4= DocStyleUtils.setParagraphStyle(contentSb4.toString(), fontChinese, 34f, 18f);   
		        contentSb5.append("4. 网络查询请登陆http://www.gzcgw.gov.cn");   
		        Paragraph bodyPar5= DocStyleUtils.setParagraphStyle(contentSb5.toString(), fontChinese, 34f, 18f);   
		        contentSb6.append("5. 以上情况经确认属实。");   
		        Paragraph bodyPar6= DocStyleUtils.setParagraphStyle(contentSb6.toString(), fontChinese, 34f, 18f);   
		        contentSb7.append("申请经办人签名：               联系电话：                 签收日期：");   
		        Paragraph bodyPar7= DocStyleUtils.setParagraphStyle(contentSb7.toString(), fontChinese, 34f, 18f);   
		        Paragraph bodyParsqdw= DocStyleUtils.setParagraphStyle(sqdwstr.toString(), fontChinese, 0f, 18f);   
		        Cell cell = new Cell(new Phrase("  流水号："+form.getAcceptNo(), fontChinese));   
		        Cell cell1 = new Cell(new Phrase("  事项类型：广州市（陆域）城市生活垃圾经营性清扫、收集、运输服务", fontChinese));   
		        Cell cell2 = new Cell(new Phrase("  申请人名称："+form.getFrdb(), fontChinese));   
		        Cell cell3 = new Cell(new Phrase("  申请日期："+DateUtilsEX.convertDate2Chinese(form.getTbrq()), fontChinese));   
		        Cell cell4 = new Cell(new Phrase("  收案人员："+username, fontChinese));   
		        Cell cell5 = new Cell(new Phrase("  收案机构："+orgname, fontChinese));   
			   
		        cell.setVerticalAlignment(Element.ALIGN_CENTER);   
		        cell.setHorizontalAlignment(Element.ALIGN_LEFT);   
		        cell.setBorderColor(new Color(0, 0, 0));   
		        cell1.setVerticalAlignment(Element.ALIGN_CENTER);   
		        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);   
		        cell1.setBorderColor(new Color(0, 0, 0));   
		        cell2.setVerticalAlignment(Element.ALIGN_CENTER);   
		        cell2.setHorizontalAlignment(Element.ALIGN_LEFT);   
		        cell2.setBorderColor(new Color(0, 0, 0));   
		        cell3.setVerticalAlignment(Element.ALIGN_CENTER);   
		        cell3.setHorizontalAlignment(Element.ALIGN_LEFT);   
		        cell3.setBorderColor(new Color(0, 0, 0));   
		        cell4.setVerticalAlignment(Element.ALIGN_CENTER);   
		        cell4.setHorizontalAlignment(Element.ALIGN_LEFT);   
		        cell4.setBorderColor(new Color(0, 0, 0));  
		        cell5.setVerticalAlignment(Element.ALIGN_CENTER);   
		        cell5.setHorizontalAlignment(Element.ALIGN_LEFT);   
		        cell5.setBorderColor(new Color(0, 0, 0)); 
		        Cell cellss = new Cell(new Phrase(" [编号]", fontChinese));   
		        Cell cellss1 = new Cell(new Phrase(" [首次提交]", fontChinese));   
		        Cell cellss2 = new Cell(new Phrase(" [份数]", fontChinese));   
		        Cell cellss3 = new Cell(new Phrase(" [非原件]", fontChinese));   
		        Cell cellss4 = new Cell(new Phrase(" [纸制]", fontChinese));   
		        cellss.setVerticalAlignment(Element.ALIGN_CENTER);   
		        cellss.setHorizontalAlignment(Element.ALIGN_LEFT);   
		        cellss.setBorderColor(new Color(0, 0, 0));   
		        cellss1.setVerticalAlignment(Element.ALIGN_CENTER);   
		        cellss1.setHorizontalAlignment(Element.ALIGN_LEFT);   
		        cellss1.setBorderColor(new Color(0, 0, 0));   
		        cellss2.setVerticalAlignment(Element.ALIGN_CENTER);   
		        cellss2.setHorizontalAlignment(Element.ALIGN_LEFT);   
		        cellss2.setBorderColor(new Color(0, 0, 0));   
		        cellss3.setVerticalAlignment(Element.ALIGN_CENTER);   
		        cellss3.setHorizontalAlignment(Element.ALIGN_LEFT);   
		        cellss3.setBorderColor(new Color(0, 0, 0));   
		        cellss4.setVerticalAlignment(Element.ALIGN_CENTER);   
		        cellss4.setHorizontalAlignment(Element.ALIGN_LEFT);   
		        cellss4.setBorderColor(new Color(0, 0, 0)); 
		        table1.addCell(cellss);  
		        table1.addCell(cellss1);  
		        table1.addCell(cellss2);  
		        table1.addCell(cellss3);  
		        table1.addCell(cellss4);   
		        for(int k=0;k<sjcl.size();k++){
		        	Map<String,String> map=sjcl.get(k);
		        	int bh=k+1;
		        	String cltitle=map.get("title");
		        	String fs=map.get("fs");
		        	String fyjs=map.get("fyjs");
		        	String zzcl=map.get("zzcl")==null?"":map.get("zzcl");
		        	 Cell cells = new Cell(new Phrase(" "+String.valueOf(bh), fontChinese));   
			         Cell cells1 = new Cell(new Phrase(" "+cltitle, fontChinese));   
			         Cell cells2 = new Cell(new Phrase(" "+fs, fontChinese));   
			         Cell cells3 = new Cell(new Phrase(" "+fyjs, fontChinese));   
			         Cell cells4 = new Cell(new Phrase(" "+zzcl, fontChinese)); 
			         cells.setVerticalAlignment(Element.ALIGN_CENTER);   
				     cells.setHorizontalAlignment(Element.ALIGN_LEFT);   
				     cells.setBorderColor(new Color(0, 0, 0));   
			         cells1.setVerticalAlignment(Element.ALIGN_CENTER);   
				     cells1.setHorizontalAlignment(Element.ALIGN_LEFT);   
				     cells1.setBorderColor(new Color(0, 0, 0)); 
					 cells2.setVerticalAlignment(Element.ALIGN_CENTER);   
					 cells2.setHorizontalAlignment(Element.ALIGN_LEFT);   
					 cells2.setBorderColor(new Color(0, 0, 0)); 
					 cells3.setVerticalAlignment(Element.ALIGN_CENTER);   
					 cells3.setHorizontalAlignment(Element.ALIGN_LEFT);   
					 cells3.setBorderColor(new Color(0, 0, 0)); 
					 cells4.setVerticalAlignment(Element.ALIGN_CENTER);   
					 cells4.setHorizontalAlignment(Element.ALIGN_LEFT);   
					 cells4.setBorderColor(new Color(0, 0, 0)); 
			         table1.addCell(cells);  
			         table1.addCell(cells1);  
			         table1.addCell(cells2);  
			         table1.addCell(cells3);  
			         table1.addCell(cells4);  
		        }
		        
		        table.addCell(cell);  
		        table.addCell(cell1);  
		        table.addCell(cell2);  
		        table.addCell(cell3);  
		        table.addCell(cell4);  
		        table.addCell(cell5);  
		        document.add(blankRow);  
		        document.add(blankRow);
		     	document.add(titlepar); 
		        document.add(blankRow); 
		        document.add(blankRow);  
		    	document.add(table); 
		    	document.add(bodyParsqdw);   
		    	document.add(bodyPar);   
		    	document.add(table1);   
		    	document.add(bodyPar1); 
		    	document.add(blankRow); 
		    	document.add(blankRow);
		    	document.add(blankRow);
		    	document.add(bodyPar2);
		    	document.add(bodyPar3);
		    	document.add(bodyPar4);
		    	document.add(bodyPar5);
		    	document.add(bodyPar6);
		    	document.add(blankRow);
		    	document.add(blankRow);
		    	document.add(blankRow);
		    	document.add(bodyPar7);
		        document.add(new Paragraph("\n")); 
		        ItextWordUtil.closeDocument(document);
			
		}
		
		
		/**
		 * 保存到ywPrintDoc表
		 * @param templateCode
		 * @param fileCode
		 * @param path
		 * @param tempdocId
		 * @param creator
		 */
		public void saveYwPrintDoc(String templateCode,String fileCode,Long ywId,String path,Long tempdocId,String creator){
			YwPrintDocForm ywPrintDocForm = new YwPrintDocForm();
			ywPrintDocForm.setYwId(ywId);
			ywPrintDocForm.setTemplateCode(templateCode);
			ywPrintDocForm.setFileCode(fileCode);
			ywPrintDocForm.setPath(path);
			ywPrintDocForm.setTempdocId(tempdocId);
			ywPrintDocForm.setCreator(creator);
			ywPrintDocForm.setCreatDate(new Date());
			ywPrintDocService.save(ywPrintDocForm);
		}
		
		@Override
		public void saveOherInfo(Map map) {
			String id=(String) map.get("id");
			String bjgzfcr=(String) map.get("bjgzfcr");
			String bjgzyy=(String) map.get("bjgzyy");
			String bjgzsj=(String) map.get("bjgzsj");
			String bjgzqd=(String) map.get("bjgzqd");
			String bjslsj=(String) map.get("bjslsj");
			String sldwcbrxm=(String) map.get("sldwcbrxm");
			String bjclqd=(String) map.get("bjclqd");
			String bjsljtdd=(String) map.get("bjsljtdd");
			String yqts=(String) map.get("yqts");
			if(StringUtils.isNotBlank(id)){
				YwHwShljqs entity = this.ywHwShljqsDao.get(Long.valueOf(id));
				
				if(StringUtils.isNotBlank(bjgzsj)){
					Date bjgzdate;
					try {
						bjgzdate = DateUtilsEX.dateFormate(bjgzsj, "yyyy年MM月dd日");
						entity.setBjgzsj(bjgzdate);//补交告知时间
					} catch (ParseException e) {
						e.printStackTrace();
					}
				}
				if(StringUtils.isNotBlank(bjslsj)){
					Date bjslsjdate;
					try {
						bjslsjdate = DateUtilsEX.dateFormate(bjslsj, "yyyy年MM月dd日");
						entity.setBjslsj(bjslsjdate);//补交受理时间
					} catch (ParseException e) {
						e.printStackTrace();
					}
				}
				if(StringUtils.isNotBlank(bjgzfcr)){
					entity.setBjgzfcr(bjgzfcr);//补交告知发出人
				}
				if(StringUtils.isNotBlank(bjgzyy)){
					entity.setBjgzyy(bjgzyy);//补交告知发出人
				}
				if(StringUtils.isNotBlank(bjgzqd)){
					entity.setBjgzqd(bjgzqd);//补交告知发出人
				}
				if(StringUtils.isNotBlank(sldwcbrxm)){
					entity.setSldwcbrxm(sldwcbrxm);//补交告知发出人
				}
				if(StringUtils.isNotBlank(bjclqd)){
					entity.setBjclqd(bjclqd);//补交告知发出人
				}
				if(StringUtils.isNotBlank(bjsljtdd)){
					entity.setBjsljtdd(bjsljtdd);//补交告知发出人
				}
				if(StringUtils.isNotBlank(yqts)){
//					entity.setYqts(yqts);//延期天数
				}
				
				this.smartFormShljqsDao.save(entity);
			}
			
		}

	
}

